Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > File Not Found Exception? when using Path.Combine() method
 

File Not Found Exception? when using Path.Combine() method

I'am send a xml file using threads and backgroundWorker control.
Source:
try
{
backgroundWorker.RunWorkerAsync(Path.Combine(Application.StartupPath, "file.xml"));
}

private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
NameValueCollection config = ConfigurationManager.AppSettings;
UploadHelper.HttpFileTransfer(e.Argument.ToString(), config["uri"]);
}

in UploadHelper

public static void HttpFileTransfer(string path, string uri)
{
WebClient client = new WebClient();
Uri currentUri = new Uri(uri);
FileInfo info = new FileInfo(path);
string filename = info.Name;
client.UploadFile(currentUri, "POST", filename);
}

When i starting release i get an FileNotFound Exception with path -> D:\ProjectRoot\ProjectFolder\file.xml. But my path contains D:\ProjectRoot\ProjectFolder\bin\Release\file.xml

Why can this happen?

Thank's
Mochnatiy  Monday, September 21, 2009 9:33 AM

The startup path of the application is where the exe is located. When you do a release build on it, the exe is generated in \bin\release, so that is where it is looking for hte file.

You need to be deploying that xml file. To do that, set the Build Action to Content, set the CopyToOutputFolder property to "copy always". Then go into the Application Files dialog and change it from Include(Data) to Include or IncludeRequired. When you do this, it will copy the xml file to the D:\ProjectRoot\ProjectFolder\bin\Release\file.xml location when you do the build, and your app can find it at System.Windows.Forms.StartupPath.

RobinDotNet


Click here to visit my ClickOnce blog!
RobinDotNet  Monday, September 21, 2009 11:35 PM

The startup path of the application is where the exe is located. When you do a release build on it, the exe is generated in \bin\release, so that is where it is looking for hte file.

You need to be deploying that xml file. To do that, set the Build Action to Content, set the CopyToOutputFolder property to "copy always". Then go into the Application Files dialog and change it from Include(Data) to Include or IncludeRequired. When you do this, it will copy the xml file to the D:\ProjectRoot\ProjectFolder\bin\Release\file.xml location when you do the build, and your app can find it at System.Windows.Forms.StartupPath.

RobinDotNet


Click here to visit my ClickOnce blog!
RobinDotNet  Monday, September 21, 2009 11:35 PM

You can use google to search for other answers

Custom Search

More Threads

• ClickOnce online only app and Shared DLL's
• mysql driver and clickonce
• bootstrap problem
• Updating a Service
• User selection-based custom action condition
• How to open a properties window of an application(right click+properties in windows)programatically in c#?
• How do I prevent ClickOnce from re-publishing prequisites that were previously published to the server?
• Setting Textbox Property Issue
• Viable click-once scenario?
• .Net architecture