文本文件目录设置 [英] Text file directory setting

查看:87
本文介绍了文本文件目录设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想知道如何将第二个表单指向我已放置文本文件的目录。基本上我有一个输入表单,将数据保存到文本文件,当我保存数据,我可以选择我想保存文本文件的位置,然后我想从文本文件中检索数据,但只能找到文本文件,如果我将它保存到我的第二个表单项目的调试文件夹。如果我将文本文件保存在该调试文件夹之外,则无法找到它。任何帮助都会很棒。



第一种形式是将文本文件保存为Calendar.txt,这样可以正常工作但是当我运行以下代码时,我得到一个错误说文件在应用程序的visual studio调试文件夹中找不到,这里有一些我的代码用于阅读文本文件,谢谢:

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.

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:

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);
           }

推荐答案

永远不要将文件保存到与应用程序执行文件夹有关的任何内容中:它会给巨大的生产中的问题,因为您的应用程序几乎肯定会安装在Program Files分支中,出于安全原因,对这些文件夹的写入权限受到严格限制。



相反,使用推荐数据文件存储位置之一:我应该在哪里存储我的数据? [ ^ ]应该有所帮助。
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.


这篇关于文本文件目录设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆