Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created a webpart in visual studio2010 which show a few images. These images are located on the servermachine. The problem is that i can not show these images to clients. When i run the webpart project on the server where the sharepoint site is located the images are displayes. When i contact the sharepointsite from a different machine it does not show the images.

The Images are loaded into a System.Web.UI.WebControls.Image object using the following code.

Image img = new Image();
img.ImageUrl = @"C:\SharePoint\Temp\Imgname.jpg";

I'd figure it's the ImageUrl that's not working but i do not know how to use or create a imageurl which a client can use.

So how do i display a image which both server and client can see on the page?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

First why the images are not appearing on the different machine, because they don't have permission on the Server Folder... The problem will be resolved by giving proper permissions...

But this approach is wrong, you should not place the images to C:\SharePoint\Temp\ folder, instead there are following options:

  • You can upload the images to one of the Libraries on SharePoint Site Collection/Site itself, let's say you have Style Library in Site Collection, you can upload the image there... Now how will you reference them, you can see Relative Paths in SharePoint...

  • If you want to use the images in several Site Collections, you should put them in _layouts/Images folder which you can find C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\Images\... Here you can make a folder and upload all the images accordingly...

I am sure then you won't have the issues you are having now, I hope this helps

share|improve this answer
    
I managed to solve the problem by simpely creating a new Virtual Directory in ISS under the Sharepoint website. Naming the directory _tempImg and directing it to the C:\SharePoint\Temp physical path. Which was a custom created path. Sorry, should have said so. And now i can acces the images by using img.ImageUrl = @"/_tempImg/" + imgName. –  user1746525 Jan 30 '13 at 13:15
add comment

put your all images into sharepoint layout images folder or create new folder in layout and set path of imageurl as "/layout/foldername/imgname.jpg"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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