This is a migrated thread and some comments may be shown as answers.

How to Upload Image in SharePoint 2010 Picture Library Using Visual WebPart

1 Answer 134 Views
Sharepoint Integration
This is a migrated thread and some comments may be shown as answers.
Siddiqali
Top achievements
Rank 1
Siddiqali asked on 12 Sep 2011, 11:45 AM
Hi to  All,
               This is siddiqali Working on Sharepoint 2010 Using Visual webpart.I am using Rad Controls .,I need to upload image in Sharepoint 2010 Picture Library using Visual Web-part .Can any one tell me how it is possible.

Thanks,
MOHAMMAD SIDDIQALI.




1 Answer, 1 is accepted

Sort by
0
Accepted
Kalina
Telerik team
answered on 27 Sep 2011, 05:16 PM
Hello Siddiqali,

You can try to upload image files in SharePoint 2010 Picture Library programmatically with RadUpload (or RadAsyncUpload) – just open the library and add the files in this way:

<telerik:RadUpload id="RadUpload1" runat="server" ControlObjectsVisibility="None" />
<asp:Button runat="server" ID="Button1" Text="Submit" OnClick="Button1_Click" />

protected void Button1_Click(object sender, System.EventArgs e)
{
    using (var site = new SPSite("http://localhost"))
    {
        using (SPWeb web = site.OpenWeb())
        {
            SPPictureLibrary pics = (SPPictureLibrary)web.Lists["MyPictureLibrary"];
 
            foreach (UploadedFile file in RadUpload1.UploadedFiles)
            {
                using (Stream fs = file.InputStream)
                {
                    pics.RootFolder.Files.Add(file.GetName(), fs);
                }
            }
 
        }
    }
}

Please find the sample attached.

Kind regards,
Kalina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Sharepoint Integration
Asked by
Siddiqali
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Share this question
or