Freigeben über


How to Upload Files to SharePoint Server 2007 from ASP.NET Web Applications

Some time ago I  blogged about How to: Uploading a File to a SharePoint Library Site from a Local Folder and How to: Magic with SharePoint 2003, uploading files using a Web service. Some people found these samples useful and some people asked if I could provide sample code that works with SharePoint Server 2007.

For some time I asked around and realized that there are multiple possible ways to accomplish this task in SharePoint 2007. Here are some popular approaches I’ve learned about and some great possibilities and drawbacks for each:

  • Copy Web service (Copy.asmx): The Copy Web service provides services for copying files within a SharePoint site and between SharePoint sites. Some people have created great samples that show you how to use this Web service to “upload” files while having some control over content types and metadata. This approach actually copies content from one SharePoint site to another, which is great, but may not be the best option if you want to upload files from your local drive to a SharePoint site.
  • Imaging Web Service (Imaging.asmx): This Web service provides methods that enable you to create and manage picture libraries. This WS has an upload method that allows you to upload different files (including non-image files) to SharePoint Image libraries (only) on the current Web site.  However, you can’t use this Web service to upload files to a regular document library (Shared Documents).
  • HTTP PUT method: There’s a third option that allows you to upload files (any file type) from your local drive to a predefined SharePoint list by using the HTTP PUT method. This method is simple and you don’t need to create SharePoint code to upload files. However, for the same reason, you won’t have programmatic control over file metadata on SharePoint lists. It’s super useful though, and I believe this is the best possible way (that I know of so far) to upload files to SharePoint Server 2007.

For this last approach, Joel Krist has created a new Office Visual How-to that shows how to use the HTTP PUT method to programmatically upload files from an ASP.NET Web application to a Microsoft Office SharePoint Server 2007 site: Uploading Files to SharePoint Server 2007 from ASP.NET Web Applications by Using the HTTP PUT Method. This article provides code samples in both VB and C# and a video that shows how to this.

Here’s a preview of the video from that same article.

Enjoy!

Comments

  • Anonymous
    July 02, 2009
    A common scenario involves moving files from a Microsoft ASP.NET Web application to a Microsoft Office Share Point Server 2007 site. Office Share Point Server provides the Copy Web service for copying files between Share Point sites or within a Share Point site, and the Imaging Web service for uploading files to Share Point image libraries. However, neither Web service supports generic file uploading to Share Point Server. This Office Visual How-To shows you how to programmatically upload files to a predefined Share Point list by using the HTTP PUT method.

  • Anonymous
    January 18, 2010
    I like the option of the HTTP PUT as it is rather simple in its approach.  How is security handled at the application layer with the puts?

  • Anonymous
    February 21, 2010
    The comment has been removed

  • Anonymous
    April 29, 2010
    Hi, Thanks for info related to "How to Upload Files to SharePoint Server 2007 from ASP.NET Web Applications" very helpul post. Cheers!

  • Anonymous
    October 11, 2010
    There's nothing enjoyable about this post, sorry. Method 1. The Copy Web Service in SP 2007 doesn't allow uploading from an external machine. Method 2. The Imaging Web Service documentation is out of date, the sample code simply doesn't work for SP 2007. (i.e. the Imaging class no longer exists, it appears to have been replaced with ImagingSoapClient) Method 3. The PUT method is useless to me as it copies to SharePoint Lists - these are of no interest to me. I've heard that they've FINALLY fixed this in the 2010 product, but why is such a basic "bread & butter" operation be seemingly impossible in SharePoint 2007? Amazing!

  • Anonymous
    October 11, 2010
    There's nothing enjoyable about this post, sorry. Method 1. The Copy Web Service in SP 2007 doesn't allow uploading from an external machine. Method 2. The Imaging Web Service documentation is out of date, the sample code simply doesn't work for SP 2007. (i.e. the Imaging class no longer exists, it appears to have been replaced with ImagingSoapClient) Method 3. The PUT method is useless to me as it copies to SharePoint Lists - these are of no interest to me. I've heard that they've FINALLY fixed this in the 2010 product, but why is such a basic "bread & butter" operation be seemingly impossible in SharePoint 2007? Amazing!