Here I explained a sample program to upload image files into picture library
spSite objSite = new SPSite(SPContext.Current.Web.Url);
try
{
byte[] imageData = null;
if (flUpload != null)
{
// This condition checks whether the user has uploaded a file or not
if ((flUpload.PostedFile != null) && (flUpload.PostedFile.ContentLength > 0))
{
Stream MyStream = flUpload.PostedFile.InputStream;
long iLength = MyStream.Length;
imageData = new byte[(int)MyStream.Length];
MyStream.Read(imageData, 0, (int)MyStream.Length);
MyStream.Close();
string filename = System.IO.Path.GetFileName(flUpload.PostedFile.FileName);
using (SPWeb myWeb = objSite.OpenWeb())
{
SPPictureLibrary pic = (SPPictureLibrary)myWeb.Lists["Images"];//Images is the picture library name
SPFileCollection filecol = ((SPPictureLibrary)myWeb.Lists["Images"]).RootFolder.Files;//getting all the files which is in pictire library
filecol.Add(filename , imageData);//uploading the files to picturte library
}
}
}
lblMessage.Text = "Uploaded successfully";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Sunday, June 21, 2009
Uploading images into picture library in sharepoint using c#
Labels:
asp.net,
c#,
picture library,
uploading images,
wss3.0.sharepoint
Subscribe to:
Post Comments (Atom)
hi ramesh
ReplyDeletehi Ramesh Can we upload a image and store that image in picture list of sharepoint default site.
ReplyDeletei had used upload file control of sharepoint. and if yes can i store loaction of that image as url in the list
Yes ..u can store
ReplyDeleteHi there,
ReplyDeleteI have a problem and want a help;
To upload an image to a library in sharepoint, I already handle but i don't know how to get it and display it on a webpage..using Object model.
If you know, pls reponse.
Thanks.