I have a file upload control in my visual web part which will enable user to select the image. I want to put it in the mapped folder.

My code is:

 if (flPicture.HasFile)
            SPSite site = SPContext.Current.Site;
            flPicture.SaveAs(site.Url+"/_layouts/Images/CommunityFormWebPart/" + flPicture.FileName);
            imgPicture.ImageUrl="_layouts/Images/CommunityFormWebPart" + flPicture.FileName;
            imgPicture.Visible = true;

But I am getting the error at line flPicture.SaveAs that the url is not rooted.

What should I do?

2 Answers 2


You can not upload files to the hive like that. In this case you would have to upload the image to a Library on your SharePoint site/web

Read more about the Hive folders here (for 2010 but still very valid if you replace 14 with 15).

Since these folders are virtual, every single site and web in your SharePoint Farm will have access to, and use the same files from these folders. That is just one of the reasons why you should not upload files from a webpart here!

Edit: To "upload" a file to a Picture Column on a list, you would:

  1. Upload the file to a Library on your site, basics shown here
  2. Bind the column on your list to that uploaded file, as shown here
  • Thank you for your response sir, any suggestion or reference to save the file directly to the list? I have a column of type Picture in my list.
    – users1100
    Commented Oct 8, 2013 at 7:24
  • Please see the update Commented Oct 8, 2013 at 7:27

just save the image to a Sharepoint Library, here's a post :http://johnlivingstontech.blogspot.com/2008/06/upload-file-to-sharepoint-document.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.