I'm working with a webpart and saving the data to a SPList. I also got two fileUpload controls and i want to upload a picture to a picture library and a document to a document library. Is that possible? And how to? Was googling around but really don't have a clue how to. I also want them to connection with other, for example, if i save the Picture to the librar i want the picture to display it's title, and not the picture url title.
This is the code i'm using when i'm uploading the image to a picture library:
byte[] imageData = null;
if (fileUpload_Pic != null)
{
if ((fileUpload_Pic.PostedFile != null) && (fileUpload_Pic.PostedFile.ContentLength > 0))
{
Stream MyStream = fileUpload_Pic.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(fileUpload_Pic.PostedFile.FileName);
SPPictureLibrary pic = (SPPictureLibrary)SPContext.Current.Web.Lists["Picture library"];//Images is the picture library name
SPFileCollection filecol = ((SPPictureLibrary)SPContext.Current.Web.Lists["Picture library"]).RootFolder.Files;//getting all the files which is in pictire library
filecol.Add(filename, imageData);//uploading the files to picturte library
}
}