日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用SharePoint 2007 Web Service上传文件到文档库

發布時間:2025/7/14 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用SharePoint 2007 Web Service上传文件到文档库 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SharePoint 2010中有了全新的客戶端模型,給我們在客戶端操作SharePoint對象提供了很大的方便,但是在SharePoint 2007中我們可以使用的方式就比較有限,Web Service是我們最常用的一種方式,SharePoint本身提供了很多web Service,比如Lists.asmx如下圖:

?

我們下面就接觸sharepoint提供的web service來實現上傳文件

1. 我們要上傳的文件如下圖:

2. 下圖為要上傳的文檔庫:

3. 實現代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MOSSUploadDemo1.*****;
using System.IO;
using System.Net;

namespace MOSSUploadDemo1
{
??? class Program
??? {
??????? static void Main(string[] args)
??????? {
??????????? string sourceFilePath = "c:\\cpu.txt";
??????????? string wsUrl="http://************/_vti_bin/copy.asmx";
??????????? string desPath="http://*******/DocLib1/filename4.txt";
??????????? string userName="****";
??????????? string password="*****";
??????????? string domain="*****";
????????????
??????????? byte[] filebyte = StreamFile(sourceFilePath);
??????????? UploadFile(filebyte,wsUrl,desPath,userName,password,domain);
??????? }

??????? private static void UploadFile(byte[] fileData,string wsUrl,string desPath,string userName,string password,string domain)
??????? {
??????????? var copy = new ****.Copy
??????????? {
??????????????? Url = wsUrl,
??????????????? Credentials = new NetworkCredential(userName, password, domain)
???????????????
??????????? };

??????????? string destinationUrl = desPath;
??????????? string[] destinationUrls = { destinationUrl };
??????????? var info1 = new FieldInformation
??????????? {
??????????????? DisplayName = "Title",
??????????????? InternalName = "Title",
??????????????? Type = FieldType.Text,
??????????????? Value = "New Title"
??????????? };
??????????? FieldInformation[] info = { info1 };
??????????? var copyResult = new CopyResult();
??????????? CopyResult[] copyResults = { copyResult };
??????????? copy.CopyIntoItems(destinationUrl, destinationUrls, info, fileData, out copyResults);
??????? }

??????? private static byte[] StreamFile(string filename)
??????? {
??????????? FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);??????????
??????????? byte[] ImageData = new byte[fs.Length];???????????
??????????? fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));???????????
??????????? fs.Close();
??????????? return ImageData;
??????????
??????? }
??? }
}

4. 程序遠行后,結果如下圖:

?

本文轉自Justin博客園博客,原文鏈接:http://www.cnblogs.com/carysun/archive/2010/12/30/moss-upload-webservice.html,如需轉載請自行聯系原作者

?

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的使用SharePoint 2007 Web Service上传文件到文档库的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。