一起谈.NET技术,使用SharePoint 2007 Web Service上传文件到文档库

简介:   SharePoint 2010中有了全新的客户端模型,给我们在客户端操作SharePoint对象提供了很大的方便,但是在SharePoint 2007中我们可以使用的方式就比较有限,Web Service是我们最常用的一种方式,SharePoint本身提供了很多web Service,比如Lists.asmx如下图:  我们下面就接触sharepoint提供的web service来实现上传文件。

  SharePoint 2010中有了全新的客户端模型,给我们在客户端操作SharePoint对象提供了很大的方便,但是在SharePoint 2007中我们可以使用的方式就比较有限,Web Service是我们最常用的一种方式,SharePoint本身提供了很多web Service,比如Lists.asmx如下图:

image

  我们下面就接触sharepoint提供的web service来实现上传文件。

  1. 我们要上传的文件如下图:

clip_image002

clip_image004

  2. 下图为要上传的文档库:

clip_image006

  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. 程序远行后,结果如下图:

clip_image008

clip_image010

目录
相关文章
|
6月前
|
监控 Cloud Native 测试技术
.NET技术深度解析:现代企业级开发指南
每日激励:“不要一直责怪过去的自己,他曾经站在雾里也很迷茫”。我是蒋星熠Jaxonic,一名在代码宇宙中探索的极客旅人。从.NET Framework到.NET 8,我深耕跨平台、高性能、云原生开发,践行领域驱动设计与微服务架构,用代码书写技术诗篇。分享架构演进、性能优化与AI融合前沿,助力开发者在二进制星河中逐光前行。关注我,共探技术无限可能!
.NET技术深度解析:现代企业级开发指南
|
SQL 小程序 API
如何运用C#.NET技术快速开发一套掌上医院系统?
本方案基于C#.NET技术快速构建掌上医院系统,结合模块化开发理念与医院信息化需求。核心功能涵盖用户端的预约挂号、在线问诊、报告查询等,以及管理端的排班管理和数据统计。采用.NET Core Web API与uni-app实现前后端分离,支持跨平台小程序开发。数据库选用SQL Server 2012,并通过读写分离与索引优化提升性能。部署方案包括Windows Server与负载均衡设计,确保高可用性。同时针对API差异、数据库老化及高并发等问题制定应对措施,保障系统稳定运行。推荐使用Postman、Redgate等工具辅助开发,提升效率与质量。
532 0
|
开发框架 数据可视化 .NET
.NET 中管理 Web API 文档的两种方式
.NET 中管理 Web API 文档的两种方式
323 14
|
开发框架 算法 .NET
C#/.NET/.NET Core技术前沿周刊 | 第 15 期(2024年11.25-11.30)
C#/.NET/.NET Core技术前沿周刊 | 第 15 期(2024年11.25-11.30)
277 6
|
开发框架 Cloud Native .NET
C#/.NET/.NET Core技术前沿周刊 | 第 16 期(2024年12.01-12.08)
C#/.NET/.NET Core技术前沿周刊 | 第 16 期(2024年12.01-12.08)
322 6
|
监控 前端开发 API
一款基于 .NET MVC 框架开发、功能全面的MES系统
一款基于 .NET MVC 框架开发、功能全面的MES系统
628 5
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
739 0
|
开发框架 前端开发 JavaScript
ASP.NET MVC 教程
ASP.NET 是一个使用 HTML、CSS、JavaScript 和服务器脚本创建网页和网站的开发框架。
365 7
|
存储 开发框架 前端开发
ASP.NET MVC 迅速集成 SignalR
ASP.NET MVC 迅速集成 SignalR
353 0
|
开发框架 前端开发 .NET
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
305 0