Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is it possible to have one button and when pressing the button i want it to save different this to two differens list , if its possible how do i solve it?...

i have created an save button that saves text in to one list , but then when pressing the same button i want it to save pictures in to an picture library.... can some help me maybe ?

SPSite site = new SPSite("http://wingtip") ;

            SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists.TryGetList("MyList");
            SPList list1 = web.Lists.TryGetList("MyLis1t");
share|improve this question

2 Answers 2

up vote 1 down vote accepted

Few examples of how to upload pictures to SharePoint picture library here and here.

First example shows how to do it if the source picture is on local hard drive, second shows if the file is coming from File Upload dialog.

Glad to be of assistance (and a Google-monkey). ;)

share|improve this answer

yes it's very easy, can you post your sample code, exactly where you are facing problem? it should be something like -

SPListItem listItem=list.Items.Add();
SPListItem list1Item=list1.Items.Add();
listItem["ColumnName"]=value;
list1Item["SecondListColumnName"]=secondValue;
listItem.Update();
list1Item.Update();

that's all, please post your code if you stuck anywhere


I am not sure how you are uploading your image file, if you are using some kind of fileupload control in your webpart, then below code may help you -

if (fileUpload.HasFile)
{
  string[] allowedExtensions = {".gif", ".png", ".jpeg", ".jpg"};
  if (allowedExtensions.Contains(System.IO.Path.GetExtension(fileUpload.FileName).ToLower()))
  {
     SPFolder picFolder = list1.RootFolder;
     picFolder.Files.Add(fileUpload.FileName, fileUpload.FileBytes);
  }
}

Here I assumed that list1 is the picture library, and fileUpload is the ID of the asp FileUpload control, and there is only one fileupload control (for multiple controls you may just tweak the code a bit and use Request.Files and HttpPostedFiles), rest of the code will be same as previous, please let me know if your requirement is different

share|improve this answer
    
He wants to upload a picture in Picture Library! –  Arsalan Adam Khatri Dec 3 '12 at 11:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.