Share via


could not find a part of the path c#

Question

Tuesday, June 10, 2014 10:06 AM

Good day guys,

Thanks for reading this.

I have gotten a network drive from my admin, in the form, \somefolder\somesubfolder, where I am supposed to deploy an application I have built. The application deploys fine, but the thing is, when the application tries to create log files in a directory called ReportLogs that is located in the same directory as the application files, I get an exception saying "could not find a part of the path C:\thisthis\thisthisandthat\applicationFolder\bin\Debug\ReportLogs\report.txt.

Can anyone please help me out or direct me to a resource that will help me out?

Thanks.

The best things in life are free, but the most valuable ones are costly...use opportunities well for there are others like you who deserves them, but don't have them...

All replies (4)

Tuesday, June 10, 2014 10:26 AM âś…Answered

Hello,

   Make sure you path is correct or have permission to access the path.

 if the reply help you mark it as your answer.
 Free Managed C# Word PDF , Excel Component(Create, Modify, Convert & Print) 


Tuesday, June 10, 2014 1:09 PM

Thank you for responding.

I know the path is correct because in Debug mode, it works fine and I am able to write to the file, but in Release mode, it doesn't work. It has problem with the mapped directory path.

Thanks.

The best things in life are free, but the most valuable ones are costly...use opportunities well for there are others like you who deserves them, but don't have them...


Tuesday, June 10, 2014 2:15 PM

Hello,

It appears that the path [C:\thisthis\thisthisandthat\applicationFolder\bin\Debug\ReportLogs\report.txt] is written to look at the project's debug folder. If the file report.txt is meant to be in the application folder where it was deployed try using the following (unless you used ClickOnce which I would suggest looking at this thread)

string FileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Report.txt");

Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.


Thursday, June 12, 2014 2:44 PM

The problem was that one of the sub directories in the path had not being created. I initially thought using the OpenOrCreate flag would create a directory along with the file to create. It turns outs the flag only cares about creating the file and hopes that the subdirectory exists.

Thanks.

The best things in life are free, but the most valuable ones are costly...use opportunities well for there are others like you who deserves them, but don't have them...