How to add images and refer to them from a web part in SharePoint 2007
-
hi there, I need to know how you can add images in a web part and contain them inside the web part so that when you deploy it on another server, the images automatically go with the whole package and get mapped automatically also. It was pretty easy with SP2010 as it has the “Mapped Folder” thing in it. So far I see a pictures library to use but you’d have to do something special for deployment purposes as I understand it. What I’m doing right now is that I am developing a web part with a grid view which would have standard icon like images in a column. What’s the best way to manage these images is what I’m looking for? Thank you very much for your help in advance! :rose:
Rocky My Blog
-
hi there, I need to know how you can add images in a web part and contain them inside the web part so that when you deploy it on another server, the images automatically go with the whole package and get mapped automatically also. It was pretty easy with SP2010 as it has the “Mapped Folder” thing in it. So far I see a pictures library to use but you’d have to do something special for deployment purposes as I understand it. What I’m doing right now is that I am developing a web part with a grid view which would have standard icon like images in a column. What’s the best way to manage these images is what I’m looking for? Thank you very much for your help in advance! :rose:
Rocky My Blog
Rocky# wrote:
you’d have to do something special for deployment purposes
No, nothing special needs to be done for development vs production. As with any .net application you can use embedded resources, which is a techniques often used by third parties when developing webparts. http://blogs.msdn.com/b/ryanrogers/archive/2006/05/01/588166.aspx[^] You can also always deploy the images to the layouts folder as with any standard SharePoint application and reference them from that location in your webpart.
No comment
-
Rocky# wrote:
you’d have to do something special for deployment purposes
No, nothing special needs to be done for development vs production. As with any .net application you can use embedded resources, which is a techniques often used by third parties when developing webparts. http://blogs.msdn.com/b/ryanrogers/archive/2006/05/01/588166.aspx[^] You can also always deploy the images to the layouts folder as with any standard SharePoint application and reference them from that location in your webpart.
No comment
add a Image mapped folder in your VS solution. Add all you images there and deploy the solution ..follow the below mentioned article from MSDN http://blogs.msdn.com/b/vssharepointtoolsblog/archive/2010/03/12/deploying-files-using-mapped-folders.aspx
-
Rocky# wrote:
you’d have to do something special for deployment purposes
No, nothing special needs to be done for development vs production. As with any .net application you can use embedded resources, which is a techniques often used by third parties when developing webparts. http://blogs.msdn.com/b/ryanrogers/archive/2006/05/01/588166.aspx[^] You can also always deploy the images to the layouts folder as with any standard SharePoint application and reference them from that location in your webpart.
No comment
Thanks for the comment Mark, I'm trying to use the embedded resources method so what I've done is I added resource file to the web part project, then I added the two pictures as resources and tried to get the URL of those by doing something like
img.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(Image), "ActivityActualSignedLarge.png");
I have also tried doing it like
My.Namespace.Name.Resources.Imagename.png
where Resources is the name of the resource file but it doesn't show the image as well. While debugging I do see a relative path but that is generated even if I input a non existent name of the image as well. So... what am I doing wrong now :( Appreciate your help!
Rocky My Blog
-
add a Image mapped folder in your VS solution. Add all you images there and deploy the solution ..follow the below mentioned article from MSDN http://blogs.msdn.com/b/vssharepointtoolsblog/archive/2010/03/12/deploying-files-using-mapped-folders.aspx
-
No I think you got it wrong because this article deals with SP 2010. I'm working in SP07. But thanks a lot anyway :)
Rocky My Blog
-
Hi It depends on the which visual Studio you are using VS2010 provides this option for SP2007 also the only difference is .. in case of SP2007 it use to map "12" hive "images" folder and for SP2010 it use to Map "14" hive "images" folder. Cheers :)
hi, I didnt know that till now. Could you please elaborate on that a bit more coz I'm working in VS2010. When I right click the solution file (or the project file too) and go to Add then I dont see any option of Adding a mapped folder or something similar. Actually I have developed a few web parts in SP2010 so I was familiar with this option as well but can't find this with SP2007. Thanks,
Rocky My Blog
-
Hi It depends on the which visual Studio you are using VS2010 provides this option for SP2007 also the only difference is .. in case of SP2007 it use to map "12" hive "images" folder and for SP2010 it use to Map "14" hive "images" folder. Cheers :)
I believe you are mistaken. With Visual Studio 2010 there is no option for creating a SP2007 solutions, only workflows. Also, the more correct, IMO, way to accomplish the task is to bundle the images as resources that are distributed in the assembly.
No comment
-
Thanks for the comment Mark, I'm trying to use the embedded resources method so what I've done is I added resource file to the web part project, then I added the two pictures as resources and tried to get the URL of those by doing something like
img.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(Image), "ActivityActualSignedLarge.png");
I have also tried doing it like
My.Namespace.Name.Resources.Imagename.png
where Resources is the name of the resource file but it doesn't show the image as well. While debugging I do see a relative path but that is generated even if I input a non existent name of the image as well. So... what am I doing wrong now :( Appreciate your help!
Rocky My Blog
Without seeing what you are actually doing there isn't much advice I can offer except make sure you have gone through the article completed and followed all of the steps. Another resource that may here is here http://support.microsoft.com/kb/910442[^]. Otherwise, there is a great deal of documentation out there for this technique, it is not specific to SharePoint, it is ASP.NET
No comment