|
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.
|
|