0

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");
1

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). ;)

-1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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