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

Using RadAsyncUpload to add files to a Sharepoint document library?

1 Answer 213 Views
Sharepoint Integration
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 25 Jan 2011, 06:27 PM
Hi

I'm working on a Sharepoint 2010 installation, and have had a bit of trouble using the ASyncUpload in a custom Visual WebPart.

I can add files to the RadUploadTemp folder fine, and in fact any folder on the 80 hive, but as far as I can tell there is no way to upload into the 14 hive. Is this correct?

In the past, I have used the standard ASP FileUploader, with an IO Stream to upload directly to the url of my Sharepoint Library, but this does not seem to work with the RAD Async Upload, I just get this error:

'http://local-sharepoint/TestLibrary' is not a valid virtual path.

If I browse to that URL normally it works fine, and works fine with a standard uplader.

Any ideas what's going on here?

Thanks for any help

1 Answer, 1 is accepted

Sort by
0
Steve
Top achievements
Rank 1
answered on 26 Jan 2011, 05:50 PM
OK, I've sorted this now.

Sharepoint Libraries and their contents are stored in SQL, rather than acutally as physical files.

I've put my code below in case it helps someone else, although I'm sure there's some stuff I could be doing better :)


<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" Skin="Windows7"
    TargetFolder="../Photos"
    onfileuploaded="RadAsyncUpload1_FileUploaded">
</telerik:RadAsyncUpload>
 
<telerik:RadButton ID="RadButton1" runat="server" Skin="Windows7" Text="Upload"
    onclick="RadButton1_Click">
</telerik:RadButton>


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using Telerik.Web.UI;
 
namespace uploaderTEST.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        String fileToUpload = @"C:\inetpub\wwwroot\wss\VirtualDirectories\80\Photos\";
        String sharePointSite = "http://local-sharepoint/TestSite/";
        String documentLibraryName = "Photos";
        String file;

protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
        {
            fileToUpload += e.UploadResult.FileName;
            Response.Write(fileToUpload);
            file = e.UploadResult.FileName;
        }
 
public void AddDoc()
        {
 
            using (SPSite oSite = new SPSite(sharePointSite))
            {
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    if (!System.IO.File.Exists(fileToUpload))
                        throw new FileNotFoundException("File not found.", fileToUpload);
 
                    SPFolder myLibrary = oWeb.Folders[documentLibraryName];
 
                    // Prepare to upload
                    Boolean replaceExistingFiles = true;
                    String fileName = file;
                    FileStream fileStream = File.OpenRead(fileToUpload);
 
                    // Upload document
                    SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
 
                    // Commit
                    myLibrary.Update();
                }
            }
        }
 
        protected void RadButton1_Click(object sender, EventArgs e)
        {
            AddDoc();
        }
     }
}

Tags
Sharepoint Integration
Asked by
Steve
Top achievements
Rank 1
Answers by
Steve
Top achievements
Rank 1
Share this question
or