Erika Ehrli - Adventures with Office Products & Technologies
MSDN & TechNet: Releasing Office, SharePoint, Exchange & Lync Centers and content for developers and IT professionals.
 

May, 2006

  • Erika Ehrli - Adventures with Office Products & Technologies

    What's new for developers in the 2007 Microsoft Office System?

    • 2 Comments

    Hi everyone!

    I had to stop blogging for a while because we were working on building an improved MSDN Office Developer Center. However, I will blog a lot starting from today to let you know about resources, developer tips, and best practices for the 2007 Microsoft Office System.

    The 2007 Microsoft Office System Beta 2 was announced today! We have been working a lot on creating new Office 2007 content and to redesign the site and here are some pointers to resources you should see!

    Check out..

    I will be blogging shortly about specific content items. In the meantime enjoy!

  • Erika Ehrli - Adventures with Office Products & Technologies

    New Office Live Blog and 2007 Microsoft Office System demos

    • 2 Comments

    The Office Live thing...

    If you want to learn more about Office Live, you should not miss Chris Beiter's blog. Chris is a Program Manager on the Solution Developer Platform portion of Office Live's next release. So for those of you who are interested in the developer story for Office Live, stick around Chris's blog.

    The Office 2007 Demo thing...

    Have you seen the MSDN TV shows published recently? If you can't wait to get to the demo, here are the links that jump into the fun part:

    Access show

    http://msdn.microsoft.com/msdntv/episodes/en/20060413AccessCC/clintcovington_demo.asx

    Excel show

    http://msdn.microsoft.com/msdntv/episodes/en/20060427ExcelDK/dannyk-shaharp_demo.asx

    SharePoint show

    http://msdn.microsoft.com/msdntv/episodes/en/20060406SharePointMF/mikefitzmaurice_demo1.asx

    http://msdn.microsoft.com/msdntv/episodes/en/20060406SharePointMF/mikefitzmaurice_demo2.asx  

    Have a great weekend!

    -Erika

  • Erika Ehrli - Adventures with Office Products & Technologies

    How to: Magic with SharePoint 2003, uploading files using a Web service

    • 69 Comments

    Some time ago I blogged about my intentions of uploading files to a SharePoint Document Library site from a local folder using some kind of Web service. After doing some research and some tests, I found a very easy way to do that and now I want to share with you the approach I followed since you might find it useful as well.

    Prerequisites

    To build this solution, you need to install Office SharePoint Portal Server 2003 and follow the next steps:

    • Create a Document Library
    • Grant access to the users that will upload files to the Document Library:

    To install the Web service:

    1. Download ODC_WritingCustomWebServicesSampleSPPT.EXE.
    2. Extract the download contents to your hard drive and Run build.bat.
      • Note: This will install the Web service on the _vti_bin virtual directory inside the Default Web Site.
    3. Open the IIS Management Console (INETMGR) and navigate to the the _vti_bin virtual directory (inside the Default Web Site).
    4. Find SPFiles.asmx, right click, and Browse.
    5. Navigate to http://localhost/_vti_bin/SPFiles.asmx to validate if you have installed successfully the Web Service.

    To consume the Web Service:

    1. From your managed application, add a reference to the http://localhost/_vti_bin/SPFiles.asmx Web Service.
    2. Call the Web service DocumentLoader
    3. Create a helper class to upload files. You can use the helper class I created.
      using System;
      using 
      System.Net;
      using 
      System.IO;
      using 
      System.Configuration;
      using 
      System.Text;
      using 
      System.Web;
      using 
      System.Security;
      using 
      System.Web.Security;
      using 
      System.Web.UI;
      using 
      System.Web.UI.WebControls;
      using 
      System.Web.UI.WebControls.WebParts;
      using 
      System.Web.UI.HtmlControls;
      using 
      DocumentLoader;

      /// <summary>
      /// A sample SharePointHelper class to upload files
      /// </summary>
      public class SharePointUploadHelper {
         
      private string _sharepointDocumentLibrary;

         public 
      SharePointUploadHelper() {
            _sharepointDocumentLibrary 
      ConfigurationManager.AppSettings["SharePointDocLibrary"];
         
      }

         
      public string UploadDocumentsToSharePoint(string fileName) {

            DocumentLoader.SPFiles svcDocLoader 
      = new DocumentLoader.SPFiles();
            
      svcDocLoader.PreAuthenticate = true;
            
      svcDocLoader.Credentials CredentialCache.DefaultCredentials;

            string 
      strPath fileName;
            string 
      strFile strPath.Substring(strPath.LastIndexOf("\\") + 1);
            string 
      strDestination _sharepointDocumentLibrary;

            
      FileStream fStream = new FileStream(strPath, System.IO.FileMode.Open);
            byte
      [] binFile = new byte[(int)fStream.Length];
            
      fStream.Read(binFile, 0, (int)fStream.Length);
            
      fStream.Close();
            string 
      result svcDocLoader.UploadDocument(strFile, binFile, strDestination);

            return 
      (result);
         
      }
      }
    4. Create a Web Form, Win Form, or console application that will require a user to upload files.
       
    5. Call the UploadDocumentsToSharePoint method of the SharePointUploadHelper class, for example:
      protected void btnLoadFile_Click(object sender, EventArgs e)
          {
              SharePointUploadHelper fh 
      = new SharePointUploadHelper();
              string 
      serverTempFilePath Server.MapPath(@"/yourApplication");
              
      contentFileUpload.PostedFile.SaveAs(serverTempFilePath);
              
      lblUploadResults.Text fh.UploadDocumentsToSharePoint(serverTempFilePath);
          
      }
    6. Open the configuration file (i.e. Web.config) and turn on impersonation.
      <identity impersonate="true" />
    7. Add a configuration key that points to the SharePoint Document Library where you will upload files.
      <add key="SharePointDocLibrary" value="http://myServerName/myDocumentLibrary"/>
    8. Build your application
    9. Run and test the application, and there, a great web service.

    I can tell you it works, just keep in mind the download is a code sample.

    Enjoy!

    -Erika

Page 1 of 1 (3 items)