WSUploadService – Web Service for uploading documents into SharePoint

来源:互联网 发布:seo属于什么专业 编辑:程序博客网 时间:2024/05/20 05:05

WSUploadService – Web Service for uploading documents into SharePoint

 

Category: MOSS 2007, WSS 3.0

WS UploadService is a web service written for Microsoft Office SharePoint Server 2007 and Windows SharePoint Services 3.0 and is meant for uploading documents into SharePoint. I have just uploaded the zip file to GotDotNet.com so it will take some time before the zip file appears in the list of downloads. For the time being, you can download the zip file from the following location:

http://www.walisystems.com/ws1_dlc.asp (Download Size: 361 KB)

The zip file contains the web service and its related files. It also contains an installer to help you install the service easily on your server. Unzip the file to your hard disk. It will create a "WSUploadService" folder. You can unzip the file anywhere on your hard disk. There is no restriction on unzipping it to a particular folder. Run "UploadServiceCopier.exe" to install the service. Installer will ask you to select a SharePoint site where this service should be installed. Select your site from the drop down and keep the folder name as "bin" (second field: textbox) and click "Next".

To uninstall, run the "UploadServiceCopier.exe" again. It will give you the following message:

"Service is already installed. Do you want to uninstall it?"

Select "Yes" and then select "Remove WSUploadService" and click "Finish" to uninstall the service. Uninstall will remove all copied files from your hard disk.

Point to remember:

1. Please run "UploadServiceCopier.exe" to install/uninstall the service. Do not run "setup.exe" directly as it will not install the service correctly.

/////////////////////////////////////////
Sample Application:           
/////////////////////////////////////////

Following is a C# sample demonstrating the use of this web service.

1. Create a .NET application.
2. Add a web reference to the web service installed on your server. For example, if you installed the web service on your default port (80), then use following url to access the web service:

http://localhost/_vti_bin/Files.asmx?wsdl

If you installed the service on another port, for example, port 17316, then the url will be:

http://localhost:17316/_vti_bin/Files.asmx?wsdl

You can also browse all web services available on the server. Files.asmx will be listed in the web services available on the server. There will be multiple entries, each entry representing the service available for a different web application. Therefore, if you want to upload documents to a site on port 80, then you should select Files.asmx for port 80.

3. Add following code to your application:

try
{
localhost.Files oUploader = new localhost.Files();

oUploader.PreAuthenticate = true;
oUploader.Credentials = CredentialCache.DefaultCredentials;

string strPath = @"C:est.doc";
string strFile = strPath.Substring(strPath.LastIndexOf("/") + 1);

string strDestination = "http://sp:17316/Docs";

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 str = oUploader.UploadDocument(strFile, binFile, strDestination);
MessageBox.Show(str);

}
catch (Exception ex)
{
MessageBox.Show(ex.Source + " – " + ex.Message + " – " + ex.InnerException + " – " + ex.StackTrace);
}

localhost is the name of the web reference that you added in previous step.

4. Run the application to test the service. "strPath" contains the filename that is to be uploaded. This is just a sample to show you how the service works, that's why i have hard coded the filename but in a real life situation you may want to add a text box and a browse button to select files from your hard disk. "strDestination" contains the destination path. This should be the path representing the document library where file is to be uploaded.

5. Finally, before testing the service, make sure the current user has privileges to upload documents in the destination document library. The user should have "Contributor" rights in the document library otherwise, you will get "401: Unauthorized" error.

Please feel free to send your comments and feedback and keep visiting the blog for more detail on the web service.

Thank you,

 

本文摘自:http://vspug.com/ssa/2006/11/30/wsuploadservice-web-service-for-uploading-documents-into-sharepoint/

原创粉丝点击