Wednesday, December 30, 2009

Add pictures to the Pictures library in Sharepoint Programmatically





Guys,
This code snippet adds a Picture to the Picture library of the sharepoint site Programmatically.

SPSite Site = new SPSite("http://Your Server Name/YourSite/");
SPWeb web = Site.OpenWeb();
web.AllowUnsafeUpdates = true;
Stream StreamImage = null;
if (FileUpload1.HasFile)
{
StreamImage = FileUpload1.PostedFile.InputStream;
}

SPList pics = web.Lists["Nitin's Picture Library"];
pics.RootFolder.Files.Add(FileUpload1.FileName, StreamImage);



That's it....

Hope it helps...

Thanks,
Nitin Sharma