Click here to Skip to main content
15,885,880 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i am looking to know how to point a second form to the directory i have placed a text file to. basically i have an input form which saves data to a text file , when I save the data, i can choose where i want to save the text file, i then want to retrieve data from the text fie but can only find the text file if i save it to the debug folder of my second forms project.so if i save the text file outside of that debug folder it cannot be found. Any help would be great.

hi, the first form is saving the text file as Calendar.txt and this works fine but when i run the following code i get an error saying the file cannot be found in the visual studio debug folder for the application, here is some of my code for reading through the text file, thanks:
C#
foreach(string line in File.ReadLines(@"C:\Calendar.txt"))
        {
           string[] items = line.Split(",".ToCharArray());
           if (items.Length >= 5)
           {
              Community_Event newEvent = new Community_Event();
              newEvent.Day = Convert.ToInt32(items[0]);//Converting the Integer to a string.
              newEvent.Time = items[1];
              newEvent.Price = Convert.ToDecimal(items[2]);//Converting the decimal to a string.
              newEvent.Event = items[3];
              newEvent.Description = items[4];
              //add the new events to the Comminity Events list.
              CommnunityEvents.Add(newEvent);
           }
Posted
Updated 26-Feb-15 18:56pm
v3
Comments
Leo Chapiro 26-Feb-15 4:14am    
And why you can't find your text file outside of debug folder? Can you see this file in windows explorer?
Tejas Vaishnav 26-Feb-15 4:16am    
what you have tried for finding text file, can you share your code so we can check where you are doing wrong. please use improve question functionality.
Sinisa Hajnal 26-Feb-15 4:21am    
Set fixed path in your app config where you save all of your files. Alternatively, after you select and save the file, save the path to it somewhere (database?) assuming you can know how to query the data (by the user or however you save the files in the first place)

1 solution

Never save files into anything to do with your application execution folder: it will give huge problems in production because your app will almost certainly be installed in the "Program Files" branch, and write access to those folders are severely limited for security reasons.

Instead, use one of the "recommended" data file storage locations: Where should I store my data?[^] should help.
 
Share this answer
 

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