How to synchronize file in TFS and SharePoint Site automatically

本文介绍如何通过编写代码实现Team Foundation Server (TFS) 版本控制系统与SharePoint站点之间的文件同步。具体步骤包括从TFS获取最新版本文件,并将其上传到指定的SharePoint站点。

Although TFS has its own Project Portal, TFS does not support synchronize files in Version Control and Portal or other SharePoint Site.

To do this, there are 2 steps:
1 Get last version file from TFS Version Control
2 Upload this file to SharePoint Site.(Any SharePoint)
Both of the 2 steps need to write code using TFS API and WSS API.

Code for Step1 (Please refer to  Get TFS Model and TFS Service Using TFS SDK)

TeamFoundationServer TFServer = TeamFoundationServerFactory.GetServer(serverName);
VersionControlServer VersionControlServer = (VersionControlServer)TFServer.GetService(typeof(VersionControlServer));

if (System.IO.File.Exists(@"c:\Requirement.txt"))
{
      System.IO.File.Delete(@"c:\Requirementc.txt");
 }
var item = TFSModal.Instance.VersionControlServer.GetItem("$/TestTFS/Document/Requirement.txt"); item.DownloadFile(@"c:\Requirement.txt");

 

Code for Step2 (need assembly Microsoft.SharePoint.dll)

I create a folder “ForUpladTest” under Document Library “Development”

You can change the URL to any other SharePoint Site if you have enough permissions.

SPSite site = new SPSite(@"http://servername/Sites/TestTFS"); 
SPWeb web = site.RootWeb;
           
SPFolder folder = web.Folders["Development"].SubFolders["ForUpladTest"];
if (folder.Exists)
{
      try
      {
            SPFile file = folder.Files["Requirement.txt"];
            file.Delete();
       }
      catch { }

      FileStream fs = new FileStream(@"c:\Requirement.txt", FileMode.Open);
      byte[] content = new byte[fs.Length];
      fs.Read(content, 0, (int)fs.Length);
      folder.Files.Add("Requirement.txt", content, true);
      fs.Close();
      folder.Update();
 }

 

After you compile these code to an application, you can use task scheduler to run it everyday.

转载于:https://www.cnblogs.com/Ruiz/archive/2009/10/20/1586914.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值