0

i have a task in sharepoint 2007. i want to upload an image using file upload control from infopath form or application page and save that image to picture library. so is there any article or code available for this question.

0

Method using Application Page:

Place a file Upload control and a button in the application page and in the button click event use the below code,

    protected void Btnupload_Click(object sender, EventArgs e)  
    {      
    using (SPSite site = new Microsoft.SharePoint.SPSite(SPContext.Current.Site.Url))      
    {
              using (SPWeb web = site.OpenWeb())    
          {   
               web.AllowUnsafeUpdates = true; 
                 Stream StreamImage = null;  
                if (FileUpload1.HasFile)  
                {        
              StreamImage = FileUpload1.PostedFile.InputStream;   
               }         
         SPList pics = web.Lists["MySamplePictureLib"];  
                pics.RootFolder.Files.Add(FileUpload1.FileName, StreamImage);   
         pics.Update();
web.AllowUnsafeUpdates = false; 

                         }    
      } 
     } 

Method using InfoPath:

Where the uploading of images are concerned, you can either write code to upload images to SharePoint document or picture libraries, or you can use one of two web services: 1. SharePoint Copy web service, or 2. SharePoint Imaging web service without having to write code.

Kindly have a look at the below URL:

  1. InfoPath form to upload an image to SharePoint (no code)

  2. Creating form in InfoPath 2010 and publishing to SharePoint 2010

  3. Upload image to SharePoint using InfoPath

| improve this answer | |

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.