开发者

Creating a text file on click of a button

I basically want to create a text file that will have contents that will be fetched from one of the tables in my Database. The contents should display as follows:-

Item1 ID1
Item2 ID2
Item3 ID3
Item4 ID4
Item5 ID5

I want the contents exactly like this. The names of the items and IDs will be diff ofcourse but the way of them appearing in th etext file should be like this.

How do I go about this? Please give me some ideas. I tried to create a file using the following code:-

  using (var sw = new StreamWriter(File.Open(@"D:\myFile.txt", FileMode.CreateNew), Encoding.GetEncoding("iso-8859-1")))
            {
        sw.WriteLine("my text...");                         
            }

and it got created fine. BUT, when I tried to create a file in C: drive, it said access to path denied. I basically want to create a map file in helicon which is installed in开发者_如何学Go c: Also once the file has been created, then again when I click a "Create File" button in my c# code, it should either delete the file and create it again or overwrite its contents with the fresh data from my Items Table. What should I do? Please help me! I am new to all this. How do I make it work ?


I had the same problem and it was due to windows 7 blocking me so i placed it in the project folder which wasn't a problem at all ,hope this helps.


Asp.net uses the NT AUTHORITY\Network Service. You need to give file access rights to this account to access your "D" drive or which ever folder you want to save the file

Check this article

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜