Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have deployed an application that has a text file that is updated with a certain value when the administrator changes something. For example, the current password that should be checked is !!Password!!. Say the admin wants to change that to @!!Password!!, the text file is updated and the new text would be the new password.

The program runs fine while debugging.. saving the password and even retreiving it when needing to check.

However, I have just deployed the application and now there is an error with everything that has something to do with that text file. Something about a path? but the text file is in my project and all paths are specified. Like i said there is absolutely NO PROBLEM in debug mode. Why wont it work once I deployed the application?

This is my error:

Could not find a part of the path 'C:\Users\Chris\AppData\Local\Apps\2.0\YCOZGQO3.6RP\Admin\AdminPass.txt'.

Thanks in advance,
Chris
Posted
Updated 15-Feb-13 1:17am
v3
Comments
Zoltán Zörgő 15-Feb-13 6:37am    
Could you give us the exact exception text you get?
Are there all needed file ACLs in place?
Are you sure the file is also deployed?
Are you sure, you are specifying the correct path? Be aware, that the while debugging, the running assambly is not what you see, is is a copy of it in the cache. Where is the file located relative to the executable and how do you specify it's path?
Christopher Smit 15-Feb-13 6:44am    
The error message is : Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.

Could not find a part of the path
'C:\Users\Chris\AppData\Local\Apps\2.0\YCOZGQO3.6RP\Admin\AdminPass.txt'.
Zoltán Zörgő 15-Feb-13 7:21am    
Let's be clear: is it a Windows Forms application or ASP.NET?
Christopher Smit 15-Feb-13 7:25am    
It is a windows forms application.
[no name] 15-Feb-13 6:41am    
are u deploy your application on IIS 7 or else because if u not configure iis7 properly the error was throw by application and its related to path and give ur error msg

1 solution

According to MSDN[^], the executing assambly path can be determined using following code sequence:
C#
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

Now use this and the System.IO.Path class[^] members to construct the path to your file.
 
Share this answer
 
Comments
fjdiewornncalwe 15-Feb-13 10:09am    
+5.
Zoltán Zörgő 15-Feb-13 13:03pm    
Thank you.
Sergey Alexandrovich Kryukov 11-Mar-13 14:41pm    
It's shorter: use System.Reflection.Assembly.GetExecutingAssembly().Location;
Besides, it's more typically should be System.Reflection.Assembly.GetEntryAssembly().Location;
(I voted 4.)
—SA
Zoltán Zörgő 11-Mar-13 16:45pm    
After my experience not all alternatives do work on the same way. This one worked for me in all situations - Location returned sometimes other locations depending on running context.
Sergey Alexandrovich Kryukov 11-Mar-13 16:59pm    
That is true, but "my" method will work the same way as "yours". Do you understand why? They have the same nature.

The problem with other methods is that they don't work or give wrong results depending on how you host an assembly (under Visual Studio host, service controller, and the like)...

—SA

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