Andere Blogs


Custom Field – Upload Files and Images  

Feb 252009

If you know my WikiWebpart or DiscussionListUploader, you know that there are some occasions where you want to upload a file, and place a link to it to another field.

The above solutions are only for the certain list type.

My new custom field can be used on every list or library!


Just add the field to one of your lists/libraries:


It will automatically try to find local libraries for documents and images to store the uploaded files and images.

One of the available list fields will be used to insert the link. That field has to be a Rich Text field! And if you want to upload and insert images, it has to be an Enhanced Rich Text field.

The great advantage of the field is, that it will be displayed when you create a new item, or edit an existing. If you view an item from the DisplayForm, the field will not be shown. And yes, it will work for new Wiki Pages!



An Update Check is implemented as in most of my solutions. That way you can always see if there is a newer version of the field available on my blog.

The field is localized for German and English.


  1. Make sure you have the .NET Framework 3.5 installed
  2. Add the solution with “stsadm –o addsolution –filename RH.UploadAndInsertField.wsp”
  3. Deploy the solution in your Central Administration



Update 24. March 2009
Fixed a bug if the field was used on a rootWeb
Update 13. July 2009 - Version
Inserted links are now relative

Update 30. June 2009 – Version
Now works as a site column

Update 06. September 2009 – Version
Fixed Bug where links for rootwebs were invalid

Update 06 Februar 2010 – Version
Fixed Bug where viewing the list in DataSheetView would fail

Posted by René Hézser | 73  Comments | Trackback Url  | 0  Links to this post | Bookmark this post with:        
Tags: Development, SharePoint, Upload Webparts
Technorati Tags: , ,

Links to this post


commented on  Monday, March 23, 2009  7:14 PM  by  Ali
I installed this control (great btw) and it appears to create the link, but the image isn't saved into the image library. I am able to save the image manually without permission errors etc..

I tried several different naming schemes on the image library as well (with/without spaces etc). I am not receiving any errors in the UI.


commented on  Tuesday, March 24, 2009  10:42 PM  by  René Hézser
Hi Ali,
I fixed the bug. You got an email with the latest release.


commented on  Saturday, April 04, 2009  12:23 AM  by  ZS
Hello René,

Thanks a lot for sharing¨it!!
Does this work in WSS3.0??
I desperately need this solution (custom field) for announcement library!!!

Need your prompt reply please


commented on  Monday, April 06, 2009  5:14 PM  by  Z-S
Hello again,

I can not deploy the source code.
When I deploy the source I get the solution in Central Administration ,but I don't get the field in created column!!
but it's works fine when I add your solution!
What should I do to deploy the source code?

commented on  Wednesday, May 20, 2009  7:50 PM  by  Brian
How about setting it so that Images can go to a different location than files. I've also noticed that I upload an image, but if I then attemt to upload a file the link is not added in the multi-line field.

commented on  Wednesday, May 20, 2009  7:54 PM  by  Brian
Ignore my post about it not putting the link for the document after an image was uploaded, I think it was just a browser odditiy. It is working now.

commented on  Friday, May 22, 2009  8:44 PM  by  Brian
Any chance the url's used to link to the content can be written as relative paths? So instead of storing it as it would just be stored as /Document%20Library%20Name/Document%20Name.doc. Reason for this is a number of SharePoint users put there SharePoint behind a proxy such as MS ISA 2006 and do domain translation. What happens is if someone uploads/inserts an image from off network via the proxy it is storing the proxy path/domain which is then not accessible from the internal network. Relative paths would eliminate this.

commented on  Wednesday, May 27, 2009  7:20 PM  by  René Hézser
Hi Brian,
I'll look into this.
In the meantime you can use linktranslation from your ISA server.


commented on  Tuesday, June 23, 2009  7:59 PM  by  Pete
This DRAMATICALLY helped us and our company. We were desperate for a web part as such. Works PERFECTLY.

Feature Request: Be able to upload multiple files at once.

Otherwise, so happy about this! Thanks!

commented on  Wednesday, June 24, 2009  9:22 AM  by  René Hézser
Glad you like this.

commented on  Wednesday, July 08, 2009  3:20 PM  by  Joe
This web part works excellently. The integrated update checker is a very useful feature.
Would it be possible for the link that is inserted into the Wiki text to be a relative link? We will be moving our MOSS install to a different server soon, I'm slightly worried that the wiki pages will continue to point at the old server. I think the relevant code is in RHUploadAndInsertControl line 140. Thanks!

commented on  Thursday, July 09, 2009  1:45 AM  by  Ben
Thank you very much for releasing this, it worked perfectly for us first time and was exactly what we needed for our site. A very professional release and much appreciated!! :)

commented on  Wednesday, July 15, 2009  12:06 AM  by  Eriq
Just found, downloaded, and installed this web part for an internal project we're working on. Unfortunately, Sharepoint is *not* my area of expertise, and I've run into a problem that I'm not sure is the result of a problem with the web part or something I've done.

I was able to add the web part using stsadm and deploy it in Central Administration. When I come to adding the column in the Site COlumn Gallery, however, I'm getting the following error:

Error in InitializeWithField: System.NullReferenceException: Object reference not set to an instance of an object. at RH.UploadAndInsertField.RHUploadAndInsertFieldEditor.FillFields() at RH.UploadAndInsertField.RHUploadAndInsertFieldEditor.InitializeWithField(SPField field)

Would appreciate any insight.


commented on  Thursday, July 23, 2009  10:17 AM  by  Maxime
Hello René,

Your update would be great, unfortunately I tried it and had a problem with the root site : the inserted link is in the form of "http://listname/filename" in the html source, which doesn't work. Checked serverRelativeUrl value, is correct ("/"), and I don't know why I get this behavior. Tried to remove the double "/" at the beginning but then it's inserting the absolute URL !!

The richtext editor seems to dislike relative path, but only for the root website !

commented on  Tuesday, July 28, 2009  5:29 PM  by  B
Hi, I'm trying to use this custom field in a site column and content type. Is this possible? If not, what would have to be done to make this possible?

commented on  Wednesday, July 29, 2009  5:50 PM  by  CP
I created this on a list and it works perfectly on the default “NewForm.aspx”
But it doesn’t work when I create my own “newItem” form. It gives me an error which says
Error in InsertLink: System.NullReferenceException: Object reference not set to an instance of an object. at RH.UploadAndInsertField.RHUploadAndInsertControl.InsertLink(SPWeb web, String filename, SPList library)
Anyway to fix this?
Thanks for your help

commented on  Thursday, August 20, 2009  2:43 AM  by  Monica
does this work on WSS 3.0? i follow the installation instructions but do not see in on the Solution Management?

commented on  Friday, August 21, 2009  8:12 PM  by  René Hézser
Hi Monica,
yes it does.
Don't copy&paste the addsolution command. Type it in yourself. Sometimes the - is not interpreted correctly.

commented on  Friday, August 28, 2009  5:33 PM  by  StephenDVick
This still does not appear to work for a root web site. Still get "http://listname/filename" in the html source.

commented on  Tuesday, September 01, 2009  7:43 PM  by  Matt Ranlett
I fixed your problem with the root web site. Change the following code:

private void InsertLink(SPWeb web, string filename, SPList library)
string fieldTitle = _FieldToInsertLink.Title;
Helper.WriteULSVerbose(string.Format("Inserting link into field '{0}'", fieldTitle));
// MATTR - fix for ServerRelativeUrl when at root of site collection
string url = @"/" != web.ServerRelativeUrl ? web.ServerRelativeUrl : web.Site.Url;
string path = string.Format("{0}/{1}/{2}", url, library.RootFolder.Url, filename);
string urlToInsert = library.BaseTemplate == SPListTemplateType.PictureLibrary ?
string.Format("<img src=\"{0}\" border=\"0\" alt=\"{1}\">", path, filename) :
string.Format("<a href=\"{0}\">{1}</a>", path, filename);
Helper.WriteULSVerbose("UrlToInser: " + urlToInsert);

commented on  Wednesday, October 14, 2009  7:53 PM  by  Jill
Love this! I would like to do a join on the list using the upload column to the Picture library to pull the thumbnail image into the joined list (because our original picture is of a larger size). Problem is that there is no matching data field from the upload into the Picture library. Any suggestions?

commented on  Sunday, October 18, 2009  10:19 AM  by  René Hézser
Hi Jill,
there is a field which might hold the information you want. SPBuiltInFieldId.Thumbnail. Take a look at it after uploading the image.


commented on  Thursday, October 22, 2009  4:34 PM  by  Mark
This _almost_ seems to be what we want, but I have a couple problems. I created a picture library on my site and specified in this field that I want pictures to go there. However, when creating a new list item, the "image" radio button is greyed out (leaving only the "document" radio button there. It seems to work, but images are going into the document library, and it will confuse our users. Am I missing a configuration option?

Also, we have a list with a "Picture" field (actually a "Hyperlink or Picture" field), which only allows you to put in a URL. I was hoping to use this to be able to upload the picture and insert the URL into the Picture field (which is not rich text). Can the part be modified to allow an upload and insert of the URL into a Picture field?

commented on  Monday, November 16, 2009  10:00 PM  by  Mike Griffin
I receive the following error on the wiki page

Error in CreateChildControls: System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. File name: 'System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' at RH.UploadAndInsertField.RHUploadAndInsertControl.GetLibraries() at RH.UploadAndInsertField.RHUploadAndInsertControl.CreateChildControls()

Any advice for a fix?

commented on  Wednesday, November 18, 2009  7:52 PM  by  René Hézser
Hi Mike,
please take a look at the first point of the installation section, and make sure you have .NET 3.5 installed on all of your frontend servers.


commented on  Thursday, November 19, 2009  11:10 PM  by  SA
Hi Rene,

I successfully added your RH.UploadandInsertField.wsp to my Sharepoint site. I also successfully deployed it.

After I deployed it, I tried looking for in my applications list, web part gallery, etc... and could not find it. I then went to '' but that did not help me either. I know I did something wrong.

Can you please help?

commented on  Tuesday, November 24, 2009  8:36 AM  by  René Hézser
after the installation and deployment, you will find a new field type if you create a new column in a list. It is not a webpart.


commented on  Thursday, November 26, 2009  12:34 AM  by  SA
Hi Rene,

I found it.. added the column to my Picture Library list. It auto-populated the document and picture library, but in 'Field to Insert Link' nothing appears in the drop-down box. What am I missing?

You help is very much appreciated! I look forward to getting your mod to work. Thank you!

commented on  Sunday, November 29, 2009  2:56 PM  by  René Hézser
>That field has to be a Rich Text field

commented on  Wednesday, December 02, 2009  1:48 AM  by  SA
How do I turn on Rich text field?

commented on  Tuesday, December 08, 2009  9:21 PM  by  René Hézser
Create a new column which supports multiple lines of text.
Then look for the options for the new column.

commented on  Monday, December 28, 2009  10:28 PM  by  Josh
How do you install this? This is the error message I receive when trying to run the addsolution command
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>"stsadm.exe -o addsolution -filename C:\RH.UploadAndInsertField.wsp"
The filename, directory name, or volume label syntax is incorrect.

Do I have to place the RH.UploadAndInsertField folder unzipped into C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES for the .wsp file to install?

commented on  Tuesday, December 29, 2009  1:49 AM  by  Josh
User error! Its working now thank you for the feature.

commented on  Wednesday, December 30, 2009  3:09 PM  by  Andreas
I have a problem and I think I don't get it :)

1) I deployed the solution which seemed to work fine.
2) The document and picutre library exist.
3) I created a new column in to the list of my wiki.
But the the document and picture library values are not auto-populated and I cannot choose them from the dropdown menue. For this reason the upload option (Picture or Document) remaines grayed out and I cannot upload nothing.

(Mein Englisch ist nicht so toll)

commented on  Thursday, February 04, 2010  8:07 PM  by  Kristen
Great tool. However, when I was trying to use your custom column in an editable DataView field, I was getting the following error:
Error in InsertLink: System.NullReferenceException: Object reference not set to an instance of an object. at RH.UploadAndInsertField.RHUploadAndInsertControl.InsertLink(SPWeb web, String filename, SPList library).

I added Matt Randlett's fix, but it didn't help. It was failing on this if statement in InsertLink method:
if (SPContext.Current.List.BaseTemplate == SPListTemplateType.DiscussionBoard)

because SPContext.Current.List is null in the DataView. I replaced the if statement with the code below to correct the problem.

if ((SPContext.Current.List != null) && (SPContext.Current.List.BaseTemplate == SPListTemplateType.DiscussionBoard))

commented on  Saturday, February 06, 2010  7:01 PM  by  René Hézser
Hallo Andreas,
die Bibliotheken müssen sich im selben Web wie die Wiki Bibliothek befinden. Sonst werden sie nicht als Auswahl für die Dropdowns gefunden.

Please make sure your libraries are within the same web as the wiki library.


commented on  Saturday, February 06, 2010  8:25 PM  by  René Hézser
Thank you Kristen,
I've fixed the bug according to your changes.


commented on  Friday, March 12, 2010  12:05 PM  by  Bernhard
Hi Rene!
Looks, that this is the feature I'm looking for.

Unfortunately I'm not able to install it.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN>stsa
dm.exe -o addsolution -filename C:\RH.UploadAndInsertField.wsp

Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
C:\RH.UploadAndInsertField.wsp: Fehler beim Installieren der Lösung.

What am I doing wrong?

commented on  Friday, March 12, 2010  12:31 PM  by  Bernhard
I figured it out:
The DB used by MOSS is on another server than MOSS itself.

You have to have administrativ privileges on both server, MOSS and DB.

commented on  Friday, March 12, 2010  7:47 PM  by  René Hézser
Hi Bernhard,
you are right :-)


commented on  Wednesday, March 31, 2010  12:43 PM  by  ricardo
Thanks Rene. Your solution saved my day. Do you know how to set up your solution in visual studio so i can deploy it from there. I'll have to do some minor changes and are fed up using stsadm.

commented on  Wednesday, April 07, 2010  5:24 AM  by  sonia
I am trying to run your source code to make Image Radio Button Selected by default, but its giving me a lot of errors. it doesnt let me build the project in visual studio. do you know any way to make image selected by default. right now its selecting document.

commented on  Wednesday, April 07, 2010  9:50 PM  by  René Hézser
Hi Ricardo,
install WSPBuilder and right click on the project. From within the "WSP Builder" menu you can create and upgrade the solution.


commented on  Wednesday, April 07, 2010  9:53 PM  by  René Hézser
Hi Sonia,
do you have SharePoint installed on the machine where you open up your VS?
In RHUploadAndInsertControl line 48 remove the Enabled and in line 49 set Enabled = true


commented on  Thursday, April 08, 2010  6:27 AM  by  Sonia Agarwal
thanks Rene...You are great...Actually i was using VS 2005. Just now i tried on VS 2008 and project is building but its creating any WSP(DONT HAVE ANY OPTION TO DEPLOY WHEN USING THIS PROJECT). But you saved my life creating this custom control.
Actually i am new in SharePoint and learning a lot from your example.
I have one more question, when i upload pic it gets populated in BODY FIELD, but picture size is too big. Is there anyway we can give fixed picture size when it uploads. Please let me know.
thanks for your time.

commented on  Thursday, April 08, 2010  9:28 PM  by  René Hézser
Hi Sonia,
good to hear it is working now :-)
Sure. You could add a width to the img tag which is inserted into the configured field.
Add the tag here: string.Format("<img src=\"{0}\" border=\"0\" alt=\"{1}\">", path, filename)


commented on  Friday, April 09, 2010  12:10 AM  by  sonia
thanks for your quick response ...can u please tell me where should i add this tag.

commented on  Friday, April 09, 2010  10:33 AM  by  René Hézser
Add just a width

commented on  Friday, April 09, 2010  8:05 PM  by  sonia
thanks Rene,

i fixed that problem...keep up the good work, u are doing a great job helping people who are new in sharepoint development. :)


commented on  Saturday, May 01, 2010  2:30 PM  by  Michael
Brilliant solution. I have been looking for something to do this for a long time. I don't understand why Microsoft didn't have this option from the beginning.


commented on  Wednesday, May 26, 2010  5:03 PM  by  Fabio
Hi Rene, thx for this solution.
I need field for only load image (not document)
What's do you think about a dropdown in field configuration for choice Only Image/Only Documents/Both ?

commented on  Wednesday, July 14, 2010  3:33 PM  by  Frederick
Thanks a lot.
It worked on first try!

commented on  Thursday, July 22, 2010  9:43 AM  by  Christoph
Vielen Dank,
das ist genau, was wir brauchten.

commented on  Wednesday, August 25, 2010  9:44 AM  by  Peter

Create wsp & deploy from source:
Install WSPBuilder from codeplex, open project in vs2008 or vs2010 and right click on project, select top entry: "WSPBuilder" and there you have commands like build vsp, deploy and lots of useful stuff

commented on  Saturday, August 28, 2010  1:56 AM  by  Renee
Both you and this solution are Brilliant!

commented on  Friday, October 15, 2010  12:19 PM  by  Braindamage
Thank you very much for this nice tool, I had a few initial problems setting it up but now got it running and it will save my customers sooooooooo much time inserting images into wikis.

I am also very impressed with the facility to be able to upload documents aswell.

Keep up the good work

commented on  Monday, February 07, 2011  11:14 AM  by  Mark
does this control run with Sharepoint 2010 ?

commented on  Monday, March 07, 2011  4:58 PM  by  AH
Hello René,
first - thanks a lot for this nice tool.

I updated the old tool to this new one. I did make sure to disable the old one on the discussion lists before updating.
But anyway, the two picture/document-dialogs are still there while editing/creating a Wiki-article. So there are both dialogs, the new and the old one.
How can I remove the old one?


commented on  Thursday, May 12, 2011  3:06 PM  by  Locke
FYI: Check for Updates returns "0.0"

commented on  Thursday, May 12, 2011  3:24 PM  by  Locke
please ignore my previous post, internet access us disabled for security reasons on the server..

commented on  Tuesday, June 14, 2011  3:48 PM  by  Joe
Hi René, We have been using your webpart for a 18 months now with great success! We will be migrating to Sharepoint 2010 in the near future - is there a version for Sharepoint 2010 planned?

commented on  Friday, July 15, 2011  1:58 AM  by  Glade
How can add the solution to Sharepoint 2010?
Please Let me know.
If cannot, when will upgrade?

commented on  Monday, August 01, 2011  11:30 PM  by  Jriesen
Yes, would love to know when you will have a version that works for SharePoint 2010. Don't need for wiki pages because SharePoint has a addressed that issue in 2010, but it would be a great tool for other lists/libraries.

Do you have any plans to put out a 2010 version?

commented on  Tuesday, September 13, 2011  10:52 PM  by  Emanuel
After I installed the web part, the Image radio button appears disabled. By default, only the document radio button is enabled. Is there something that needs to be done to enable the Image radio input? Did anyone else encounter this?

commented on  Thursday, October 20, 2011  7:32 AM  by  max_xxx
Hi, Rene
I can't rebuild your sources.
Trying in VS 2010
Install WSPBuilder.
When i run Build WSP - get error 'Wrong parameter. Exception HRESULT:0x80070057 (E_INVALIDARG)'

Can you publish link to WSP, which you are use?
Maybe i can add something to your project and it cat build in VS 2010?

Please, help me if you can

commented on  Tuesday, January 03, 2012  5:13 AM  by  Revi Tantular
Dear René,

thanks, this help me a lot. and it works on 2007.
Nice tools, simple but very useful.

commented on  Wednesday, January 18, 2012  12:59 PM  by  Shivaji
Thanks for the solution. I tried to deploy this solution to Sharepoint 2010. Its observed that its inserting the attachements details only in the description column not with any other column name having the RichText format.

Kindly give me some idea to fix this issue.

Thanks & Regards,

commented on  Tuesday, April 03, 2012  1:28 PM  by  Shivaji
Hello Rene,

I have added your solution on Sharepoint 2010. It works perfect on IE but on FF it shows the HTML source for Richtext box that we are using for the Attachment details.

Can you Please suggest the solution on this ?

commented on  Friday, June 22, 2012  3:07 PM  by  fh123
thanks so much for your solution! I need it for our company blog, to be able to upload pics in new blogitems and to display them on blog frontpage. this can get archived by editing postlist.xsl in Codeplex's Enhanced Blog Framework.
If anyone needs more information about that, mail me.


commented on  Thursday, September 20, 2012  3:13 PM  by  Prakash
This code is a real lifesaver! I have been searching for weeks for this solution. Many thanks Rene- you're a star! I deployed it in SP2010 with no issues whatsover but I cannot get url link to be displayed in the Enhanced Rich text box? I have the picture library enabled. The image upload works and the image is inserted in the picture library but no links are displayed in Enhance RTB? The Files loaded option is also set in the "field to insert link". Where am I going wrong?

commented on  Friday, September 21, 2012  12:24 PM  by  Prakash
Just discovered that the solution does not work if you creating a custom site page. The only reason that I am using custom site page is that with a custom edit forms, I cannot get paging to work whereas it works in site page. Anyone experience this problem and advise me of a solution? If paging can work in custm forms then my problems are all solved.


commented on  Thursday, January 24, 2013  12:07 PM  by  fahad
is there any way to remove the Image option i need only file option to upload the documents.

commented on  Monday, March 25, 2013  12:58 PM  by  ebrookhouse
I spent some time trying to get this fully functional in SP2010 and SP2013, no luck. The module installs, but logic to figure out which field to store the link in doesn't work. If anyone has any luck getting this to work please re-post.



Name *:

CAPTCHA Image Validation