locked
How to read image file from a URL and save the image in picture library in sharepoint 2010 RRS feed

  • Question

  • Hi,

    I have a custom list in SharePoint 2010 which contains a column named ImageURL. This ImageURL column contains a URL which specifies an image which is stored on another server.

    eg:

    http://urn2.dss.com/Imagefolder/cust.png

    What I need to do is read this image from this URL in my class file in C# and store the image in the Picture library in SharePoint 2010.

    Then in my custom list, in the ImageURL column instead of specifying the URL which is present on the another server, I will give the relative URL for the SharePoint Picture library where the image is stored.

    Could you please let me know how can I download this image by specifying the URL for the image and place it the Picture Library in my SharePoint site? If someone could share some code that specifies how this can be done the it would be very helpful.

    Thanks in advance.

    Regards,

    Raj



    • Edited by Raj190 Saturday, January 26, 2013 6:22 PM
    Saturday, January 26, 2013 6:15 PM

Answers

  • You can do this simply by using the System.Net.WebClient. You can also modify the code to take a destination picture library url as an argument. Hope this helps.

    public static string CreateImageFromRemoteImage(string remoteUrl)
    {
    
                Uri remoteUri = new Uri(remoteUrl);
                string fileName = Path.GetFileName(remoteUri.LocalPath);
                WebClient wc = new WebClient();
                wc.UseDefaultCredentials = true;
                byte[] response = wc.DownloadData(remoteUrl);
                string destination = "http://basesmc2008/pictures/" + fileName;
                byte[] response2 = wc.UploadData(destination, "PUT", response);
    
                return destination;
                
    }


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    Saturday, January 26, 2013 7:17 PM

All replies

  • You can do this simply by using the System.Net.WebClient. You can also modify the code to take a destination picture library url as an argument. Hope this helps.

    public static string CreateImageFromRemoteImage(string remoteUrl)
    {
    
                Uri remoteUri = new Uri(remoteUrl);
                string fileName = Path.GetFileName(remoteUri.LocalPath);
                WebClient wc = new WebClient();
                wc.UseDefaultCredentials = true;
                byte[] response = wc.DownloadData(remoteUrl);
                string destination = "http://basesmc2008/pictures/" + fileName;
                byte[] response2 = wc.UploadData(destination, "PUT", response);
    
                return destination;
                
    }


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    Saturday, January 26, 2013 7:17 PM
  • You can resolve you problem easily by reading the article having link...

    http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/fetching-image-from-sharepoint-2007-picture-library-using-object-model/

    Sunday, January 27, 2013 5:37 AM