I was trying to upload images to a Pictures Library, and getting thumbnailing working, and so on. I found that thumbnailing wasn’t working, so I kept trying to create and upload my own thumbnail, which was pretty dumb. SharePoint will do that for you – but you’ve got to upload your file with a correct extension for an image format…
The code that worked was:
SPPictureLibrary pics = (SPPictureLibrary)site.Lists["Pictures"];
FileStream fs = new FileStream(@"c:lolrus.jpg",FileMode.Open,FileAccess.Read);
Previously I’d been trying this for the final line:
The thumbnails weren’t being generated because I failed to have the .jpg extension. I guess I figured I was defining the Display Name of the item, rather than the file name. I added in the ‘.jpg’ and when I uploaded my image, thumbnails were automatically generated. Nice.
2 thoughts on “WSS Practice: Upload image to a Pictures Library”
Good concept in article….
Nice to go through…if possible elaborate so that new to MOSS people can understand easily…
Not really a lot more to say. Create yourselve an SPWeb object, then get your Picture library as above (“site” is an SPWeb object).
This article describes getting an SPWeb object:
You’ll need to reference and use the Microsoft.SharePoint assembly – so this code will only run on the server 😦 If you need it to work remotely, well, you’re looking at having to use web services then.