Files Uploading in Sharepoint Document Library with RadAsyncUpload

1 posts, 0 answers
  1. ice
    ice avatar
    1 posts
    Member since:
    Nov 2006

    Posted 11 Jul 2014 Link to this post

    Here is how you can upload files in Sharepoint Document Library:
    1. Create a new Visual Web Part
    2. Add reference to Telerik.Web.UI assembly
    3. Register Telerik.Web.UI assembly:
      <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
      <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
      <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
      <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
      <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
      <%@ Import Namespace="Microsoft.SharePoint" %>
      <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
      <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1.ascx.cs" Inherits="VisualWebPartProject1.VisualWebPart1.VisualWebPart1" %>
      <%@ Register Assembly="Telerik.Web.UI, Version=2014.2.618.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
       
      <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" ></telerik:RadAsyncUpload>
      <telerik:RadButton runat="server" Text="Submit" ID="RadButton1" OnClick="RadButton1_Click"></telerik:RadButton>
    4. Save the file
    protected void RadButton1_Click(object sender, EventArgs e)
            {
                foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles)
                {
                    String sharePointSite = "http://ajax-sp2010/";
                    String documentLibraryName = "Shared Documents";
     
                    using (SPSite oSite = new SPSite(sharePointSite))
                    {
                        using (SPWeb oWeb = oSite.OpenWeb())
                        {
                            SPFolder myLibrary = oWeb.Folders[documentLibraryName];
     
                            Boolean replaceExistingFiles = true;
                            // Upload document
                            SPFile spfile = myLibrary.Files.Add(file.FileName, file.InputStream, replaceExistingFiles);
     
                            // Commit
                            myLibrary.Update();
                        }
                    }
                }
            }

    Note that when file is selected it is uploaded in the App_Data folder:
    C:\inetpub\wwwroot\wss\VirtualDirectories\80\App_Data\RadUploadTemp
Back to Top