Click here to Skip to main content
15,885,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using the following code to retrieve a file from TFS. The method executes without error but when I try to access the downloaded file, I get an error saying the file cannot be found.
I think there is a delay between "DownloadFile" and actually putting the file on my local.
Any suggestions?

C#
public static void GetFileFromTFS(string filePath, string filename)
  {       
   try
   {
    string fileStr = null;
    _server.Authenticate();
    WorkItemStore store = new WorkItemStore(_server);
    Item file = null;
    fileStr = filePath  + filename;
    file = _versionControl.GetItem(fileStr);
    file.DownloadFile(filePath + Path.GetFileName(file.ServerItem)); 
    }
     catch (Exception ex)
      { Trace.WriteLine("Unknown Error.  Message returned: \n" +     
                         ex.Message, "Unknown Error");
      }
         
}
Posted
Updated 13-Oct-11 9:28am
v4

1 solution

Is the file there if you look for for it yourself? If you wouldn't know where to look, then the problem is obvious. You would need to create a workspace.

http://msdn.microsoft.com/en-us/library/ms181384.aspx[^]

For your code to work it would also need to exist in the workspace. By the way... when combining a path and a filename you might want to consider using Path.Combine(filePath + Path.GetFileName(file.ServerItem));

You could also specify both serverpath and localpath:
http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.downloadfile%28v=vs.80%29.aspx[^]

Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900