色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

使用SharePoint 2007 Web Service上傳文件到文檔庫

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

image

  我們下面就接觸sharepoint提供的web service來實現(xiàn)上傳文件。

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

clip_image002

clip_image004

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

clip_image006

  3. 實現(xiàn)代碼如下:

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;
}
}
}

NET技術(shù)使用SharePoint 2007 Web Service上傳文件到文檔庫,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 项城市| 十堰市| 青浦区| 井陉县| 富裕县| 北票市| 民勤县| 杭锦后旗| 旬邑县| 通城县| 上杭县| 贺兰县| 九台市| 德昌县| 普兰店市| 安福县| 昭通市| 德江县| 棋牌| 日喀则市| 安图县| 甘洛县| 涡阳县| 石城县| 都昌县| 甘泉县| 厦门市| 芷江| 大冶市| 雷山县| 平湖市| 贡嘎县| 黎城县| 喀喇沁旗| 祁东县| 温宿县| 房产| 黄陵县| 苗栗县| 新巴尔虎左旗| 应城市|