|
I have had this problem before and it suddenly vanished, however I am not having any luck this time. I have 12 text files that my files reads and writes to and it works fine in visual studios, but when I try to install the deployed version I immediately get a file not found error. I have tried different stuff with the files such as setting the build action to "Content" "None" and changing the copy action to "copy always" and "dont copy", but nothing has worked. I have also tried not using the .deploy extension. The files are getting copied into the application files folder. Does anyone know what would cause this or how to fix it? The weird thing is that on my other program the copy action is set to "do not copy" but it does copy and it installs properly. So I am really confused. - Moved byOmegaManMVPFriday, July 03, 2009 10:30 PM (From:Visual C# General)
-
|
| Zero_gt Thursday, July 02, 2009 1:25 AM |
Hi,
I would look at the physical path of the files in both locations. For example, put a trace statement that logs the file path when you are trying to access the file. Also, compare that to the Server.MapPath(".") value, which will be your application root folder.
Joe Free C# Tutorial @
http://www.csharp-station.com- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Joe Mayo Thursday, July 02, 2009 2:30 PM |
Hi, Could you please post the code that accesses these text file? How do you deploy these files ? Are they stored at right place? Harry
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Harry Zhu Friday, July 03, 2009 6:38 AM |
Hi Zero_gt, Based on your words I think you are using setup project (msi) to deploy your project. Am I guess right? If I misunderstand it, please feel free to tell me. Then I guess you have add that file to your project, not setup project but your application project. You change the "Copy to output directory" property in the property window. It doesn't take effect. I suggest you should add that file into setup project once it is missing from that. Right click the "Application Folder" node in the setup project, choose "Add" -> "File", add it to the current folder. Then your file should be include in the target directory. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Kira Qian Monday, July 06, 2009 2:45 AM |
Hi Zero_gt, Your last post indicate you are using ClickOnce. Right click your project and turn into the properties page. Choose the publish page. Then click the "Application Files..." button. The popup dialog will list the files, please make sure your added files have been marked as "Include". Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Kira Qian Tuesday, July 07, 2009 2:27 AM |
Hi, Please look into the application folder For Win XP/2003 C:\Documents and Settings\[Your user name]\Local Settings\Apps\2.0 For Vista/2008 C:\Users\[Your user name]\AppData\Local\Apps Are these files loacated there? Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Kira Qian Thursday, July 09, 2009 1:49 AM |
First, set Build Action = "Content", and Copy to "Copy Always" on your files.
Also, change the property for appending ".deploy" back to append that. If you don't, then it will be difficult for people to install your app, as most people have antivirus software, and it won't let dll's through.
The next thing you need to know is you need to specify a path for picking up those text files. If they are in the top level of your project, you can access them by appending the file name with the path to them, like this:
string myFileName = Path.Combine(System.Windows.Forms.Application.StartupPath, "thisismyfile.txt");
My guess is it can't find them because you are not specifying the whole path.
If you have them in a subfolder under your main project, you need to append that to the StartupPath before the file name.
RobinDotNet Click here to visit my ClickOnce blog!- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| RobinDotNet Thursday, July 09, 2009 2:02 AM |
It's more likely that it can't find the file (filenotfoundexception).
First, you misunderstood about the .deploy -- you DO want to include that.
Second, did you add the files to your project, and if so, are they in a subfolder, or are they in the project itself as files?
RobinDotNet Click here to visit my ClickOnce blog!- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| RobinDotNet Monday, July 13, 2009 4:55 AM |
This is exactly what you needed to do == add the files to the project. Click on each file, set Build Action = content, and Copy To Output Directory = copy always. When you build the solution, it will copy the files into the bin folder. You can access the files by using the StartupPath property like this: string myFileIsAt = Path.Combine(System.Windows.Forms.Application.StarupPath, "thisismyfile.txt"); If (File.Exists(myFileIsAt)) //file exists Note: If they are XML files, ClickOnce sets them to be deployed as data. You can change that by bringing up the Application Files dialog and finding the files, and change "Include(Data)" to "Include(Required)". (Per your next post, it has nothing to do with Resources if the files reside in the top level of your project as you have said they do). RobinDotNet Click here to visit my ClickOnce blog!- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| RobinDotNet Tuesday, July 21, 2009 6:18 AM |
Hi,
I would look at the physical path of the files in both locations. For example, put a trace statement that logs the file path when you are trying to access the file. Also, compare that to the Server.MapPath(".") value, which will be your application root folder.
Joe Free C# Tutorial @
http://www.csharp-station.com- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Joe Mayo Thursday, July 02, 2009 2:30 PM |
How do I create a trace statement and where is this Server.MapPath in the root folder at? |
| Zero_gt Thursday, July 02, 2009 3:52 PM |
Hi, Could you please post the code that accesses these text file? How do you deploy these files ? Are they stored at right place? Harry
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Harry Zhu Friday, July 03, 2009 6:38 AM |
Well the files are accessed many times throughout the application but an example would be: string line; streamreader sr = new streamreader("file.txt"); line = sr.readline(); -I do a lot of reading and writting to the files using that method and a few appending. -The text files are stored in the debug/bin folder currently since that is the default area a program looks for files and I don't have to put a path that way. -I just let the files deploy however they normally do. They get put in the application files folder as .txt.deploy extensions and they all seem to be there. -I wish the error report would say which file it can't find so I could isolate the problem. -I am assuming they are stored in the correct place because I have not done anything different in this application than in past ones and they worked better. The only difference is that this one is much more complex and has more file accesses. But since it works fine in Visual Studio it must be some sort of deploy issue?
|
| Zero_gt Friday, July 03, 2009 9:29 PM |
Hi Zero_gt, Based on your words I think you are using setup project (msi) to deploy your project. Am I guess right? If I misunderstand it, please feel free to tell me. Then I guess you have add that file to your project, not setup project but your application project. You change the "Copy to output directory" property in the property window. It doesn't take effect. I suggest you should add that file into setup project once it is missing from that. Right click the "Application Folder" node in the setup project, choose "Add" -> "File", add it to the current folder. Then your file should be include in the target directory. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Kira Qian Monday, July 06, 2009 2:45 AM |
I am not exactly sure if I am using (msi). I am just clicking "publish <project name>" from the main toolbar. Currently I have the files in the bin/debug folder and I also added them by right clicking the project and clicking "add existing item". This has caused some problems because the program is only updating one set of the files while reading from the other set. So are ou saying I need to change it to "Copy to output directory"? |
| Zero_gt Monday, July 06, 2009 5:02 PM |
Hi Zero_gt, Your last post indicate you are using ClickOnce. Right click your project and turn into the properties page. Choose the publish page. Then click the "Application Files..." button. The popup dialog will list the files, please make sure your added files have been marked as "Include". Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Kira Qian Tuesday, July 07, 2009 2:27 AM |
Yes they are all set to include(required). |
| Zero_gt Wednesday, July 08, 2009 6:59 PM |
Hi, Please look into the application folder For Win XP/2003 C:\Documents and Settings\[Your user name]\Local Settings\Apps\2.0 For Vista/2008 C:\Users\[Your user name]\AppData\Local\Apps Are these files loacated there? Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| Kira Qian Thursday, July 09, 2009 1:49 AM |
First, set Build Action = "Content", and Copy to "Copy Always" on your files.
Also, change the property for appending ".deploy" back to append that. If you don't, then it will be difficult for people to install your app, as most people have antivirus software, and it won't let dll's through.
The next thing you need to know is you need to specify a path for picking up those text files. If they are in the top level of your project, you can access them by appending the file name with the path to them, like this:
string myFileName = Path.Combine(System.Windows.Forms.Application.StartupPath, "thisismyfile.txt");
My guess is it can't find them because you are not specifying the whole path.
If you have them in a subfolder under your main project, you need to append that to the StartupPath before the file name.
RobinDotNet Click here to visit my ClickOnce blog!- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| RobinDotNet Thursday, July 09, 2009 2:02 AM |
I looked in my Apps\2.0 folder and had to navigate down a little bit further into some strangely named folders but the files were in there. -I have my files set to Content and Copy Always. I also set it to not use ".deploy" because I think that is what you wanted me to do? -What do you mean by if my files are in "top level of the project"? -Is this what you are thinking I need to do to all of the file access areas?: StreamReader sr2 = new StreamReader(Path.Combine(System.Windows.Forms.Application.StartupPath,"MyFile.txt")); |
| Zero_gt Thursday, July 09, 2009 10:01 PM |
I have since changed all of the code that accesses the files to include the path code you stated above. However, the same problem is persisting. This is the actual error message I am getting if it helps: EventType : clr20r3 P1 : myProgram.exe P2 : 1.0.0.0 P3 : 4a579809 P4 : system.drawing P5 : 2.0.0.0 P6 : 4889dec2 P7 : 144 P8 : 14 P9 : system.io.filenotfoundexception ![]() |
| Zero_gt Friday, July 10, 2009 7:41 PM |
Could this error occur if I didn't close a stream reader/writer somewhere? It seems that what ever is causing this problem is something unusual I guess so I can't figure it out. |
| Zero_gt Sunday, July 12, 2009 4:59 PM |
It's more likely that it can't find the file (filenotfoundexception).
First, you misunderstood about the .deploy -- you DO want to include that.
Second, did you add the files to your project, and if so, are they in a subfolder, or are they in the project itself as files?
RobinDotNet Click here to visit my ClickOnce blog!- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| RobinDotNet Monday, July 13, 2009 4:55 AM |
At first I had all the files in the debug/bin folder, but in order to get them to show up as application files I had to add them into the project. When I did this they were added into what I would call the root folder which is where the solution and the window form files are located. The files are technically in both locations. Is that a problem? The files are not in any sort of subfolder in these locations they are just sitting in there along side the rest of the files and such. |
| Zero_gt Monday, July 13, 2009 7:06 PM |
In the applications settings I see a tab called "resources". Is it possible that I need to do anything there? -If I add a catch for the filenotfoundexception I could theoretically track down the issue right?(unless there is something wrong with all the file accesses). |
| Zero_gt Thursday, July 16, 2009 7:26 PM |
This is exactly what you needed to do == add the files to the project. Click on each file, set Build Action = content, and Copy To Output Directory = copy always. When you build the solution, it will copy the files into the bin folder. You can access the files by using the StartupPath property like this: string myFileIsAt = Path.Combine(System.Windows.Forms.Application.StarupPath, "thisismyfile.txt"); If (File.Exists(myFileIsAt)) //file exists Note: If they are XML files, ClickOnce sets them to be deployed as data. You can change that by bringing up the Application Files dialog and finding the files, and change "Include(Data)" to "Include(Required)". (Per your next post, it has nothing to do with Resources if the files reside in the top level of your project as you have said they do). RobinDotNet Click here to visit my ClickOnce blog!- Marked As Answer byZero_gt Wednesday, July 22, 2009 2:28 AM
-
|
| RobinDotNet Tuesday, July 21, 2009 6:18 AM |
Well, I guess I am a total idiot. I was so focused on the text files that I never thought that the problem could be the image files I used in the application. I forget to add them into the project. At least I learned a lot about how the files are accessed through all your help though.
|
| Zero_gt Wednesday, July 22, 2009 2:04 AM |
You're not a total idiot. Once you know how to do something, it always seems obvious! Glad I was able to help you.
RobinDotNet Click here to visit my ClickOnce blog! |
| RobinDotNet Wednesday, July 22, 2009 3:43 PM |