Custom Field – Upload Files and Images

Custom Field – Upload Files and Images

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!

image

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

image

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!

image

 image

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.

Installation

  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

Download:

RH.UploadAndInsertField.wsp

RH.UploadAndInsertField-Source.zip

Update 24. March 2009

Fixed a bug if the field was used on a rootWeb

 

Update 13. July 2009 – Version 1.0.2.0
Inserted links are now relative

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

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

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

73 Comments

Ali

Reply

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.

Thanks,
Ali

 

René Hézser

Reply

Hi Ali,
I fixed the bug. You got an email with the latest release.

René

 

ZS

Reply

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

Thanks

 

Z-S

Reply

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?

 

Brian

Reply

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.

 

Brian

Reply

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.

 

Brian

Reply

Any chance the url’s used to link to the content can be written as relative paths? So instead of storing it as http://site.domain.com/Document%20Library%20Name/Document%20Name.doc 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.

 

René Hézser

Reply

Hi Brian,
I’ll look into this.
In the meantime you can use linktranslation from your ISA server.

René

 

Pete

Reply

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!

 

René Hézser

Reply

🙂
Glad you like this.
René

 

Joe

Reply

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!

 

Ben

Reply

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!! 🙂

 

Eriq

Reply

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.

-eriq

 

Maxime

Reply

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 !

 

B

Reply

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?

 

CP

Reply

Hello,
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

 

Monica

Reply

does this work on WSS 3.0? i follow the installation instructions but do not see in on the Solution Management?

 

René Hézser

Reply

Hi Monica,
yes it does.
Don’t copy&paste the addsolution command. Type it in yourself. Sometimes the – is not interpreted correctly.
René

 

StephenDVick

Reply

This still does not appear to work for a root web site. Still get “http://listname/filename” in the html source.

 

Matt Ranlett

Reply

I fixed your problem with the root web site. Change the following code:

private void InsertLink(SPWeb web, string filename, SPList library)
{
try
{
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(“”, path, filename) :
string.Format(“{1}“, path, filename);
Helper.WriteULSVerbose(“UrlToInser: ” + urlToInsert);

 

Jill

Reply

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?

 

René Hézser

Reply

Hi Jill,
there is a field which might hold the information you want. SPBuiltInFieldId.Thumbnail. Take a look at it after uploading the image.

René

 

Mark

Reply

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?

 

Mike Griffin

Reply

I receive the following error on the wiki page

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

Any advice for a fix?

 

René Hézser

Reply

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.

René

 

SA

Reply

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 ‘http://www.hezser.de/blog/Lists/Beitraege/Post.aspx?ID=118’ but that did not help me either. I know I did something wrong.

Can you please help?

 

René Hézser

Reply

Hi,
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.

René

 

SA

Reply

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!

 

René Hézser

Reply

>That field has to be a Rich Text field

 

SA

Reply

How do I turn on Rich text field?

 

René Hézser

Reply

Create a new column which supports multiple lines of text.
Then look for the options for the new column.

 

Josh

Reply

How do you install this? This is the error message I receive when trying to run the addsolution command
C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN>”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 FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES for the .wsp file to install?

 

Josh

Reply

User error! Its working now thank you for the feature.

 

Andreas

Reply

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)

 

Kristen

Reply

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))

 

René Hézser

Reply

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.

René

 

René Hézser

Reply

Thank you Kristen,
I’ve fixed the bug according to your changes.

René

 

Bernhard

Reply

Hi Rene!
Looks, that this is the feature I’m looking for.

Unfortunately I’m not able to install it.

C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12BIN>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?

 

Bernhard

Reply

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.

 

René Hézser

Reply

Hi Bernhard,
you are right 🙂

René

 

ricardo

Reply

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.

 

sonia

Reply

Hi,
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.
thanks

 

René Hézser

Reply

Hi Ricardo,
install WSPBuilder and right click on the project. From within the “WSP Builder” menu you can create and upgrade the solution.

René

 

René Hézser

Reply

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

René

 

Sonia Agarwal

Reply

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.
Sonia

 

René Hézser

Reply

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(“”, path, filename)

René

 

sonia

Reply

Rene,
thanks for your quick response …can u please tell me where should i add this tag.
thanks
sonia

 

René Hézser

Reply

http://www.w3schools.com/tags/tag_IMG.asp
Add just a width

 

sonia

Reply

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. 🙂

Sonia

 

Michael

Reply

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.

thanks
Michael.

 

Fabio

Reply

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 ?

 

Frederick

Reply

Thanks a lot.
It worked on first try!
Frederick

 

Christoph

Reply

Vielen Dank,
das ist genau, was wir brauchten.

 

Peter

Reply

THANK YOU, HELPED ME A LOT!!!!

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

 

Renee

Reply

Both you and this solution are Brilliant!

 

Braindamage

Reply

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

 

Mark

Reply

does this control run with Sharepoint 2010 ?

 

AH

Reply

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?

Andreas

 

Locke

Reply

FYI: Check for Updates returns “0.0”

http://imageshack.us/photo/my-images/18/85796682.png/

 

Locke

Reply

please ignore my previous post, internet access us disabled for security reasons on the server..

 

Joe

Reply

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?

 

Glade

Reply

Hello!!
How can add the solution to Sharepoint 2010?
Please Let me know.
If cannot, when will upgrade?

 

Jriesen

Reply

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?

 

Emanuel

Reply

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?

 

max_xxx

Reply

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

 

Revi Tantular

Reply

Dear René,

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

 

Shivaji

Reply

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,
Shivaji

 

Shivaji

Reply

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 ?

 

fh123

Reply

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.

fh123

 

Prakash

Reply

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?

 

Prakash

Reply

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.

Prakash

 

fahad

Reply

is there any way to remove the Image option i need only file option to upload the documents.

 

ebrookhouse

Reply

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.

Thanks.

Edward

 

Leave a Reply