protected bool DownloadLatestVersionFromTFS(string serverURL, string serverPath, string localFile, bool setReadOnly) { if (string.IsNullOrEmpty(localFile) || string.IsNullOrEmpty(serverURL) || string.IsNullOrEmpty(serverPath)) throw new ArgumentException("Object reference not set to an instance of an object."); ICredentialsProvider provider = new UICredentialsProvider(); using (TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(serverURL), provider)) { Logger.GetInstance().WriteLog("Connecting to TFS on " + serverURL + "..."); tfs.Authenticate(); Logger.GetInstance().WriteLog("Get latest version: " + serverPath + "..."); VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); vcs.DownloadFile(serverPath, localFile); if (File.Exists(localFile)) { Logger.GetInstance().WriteLog("Download complete."); // set the read-only bit on the downloaded file if (setReadOnly==true) File.SetAttributes(localFile, FileAttributes.ReadOnly); return true; } else { Logger.GetInstance().WriteLog("Download failed."); return false; } }
Logger
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)