hiee,
Normally v create a text file using textwriter i.e,
TextWriter txt = new StreamWriter("path");
but in my case i need 2 create a text file whose name comes from database.
for example: i need 2 create a file with its name as each individual's mobile number which is stored in database.something like 1234567898.txt in which this number is retrieved frm database.
i tried doing something lik,
DataRow dr = ds.Tables[0].Rows[0];
string number = dr[5].ToString();
string path = "C:/"+number+".txt";
TextWriter txt = new StreamWriter(path);
But the error message says this path structure is not supported..
Wat can b done to solve this problem..?
Thanks in advance,
Soumya
Normally v create a text file using textwriter i.e,
TextWriter txt = new StreamWriter("path");
but in my case i need 2 create a text file whose name comes from database.
for example: i need 2 create a file with its name as each individual's mobile number which is stored in database.something like 1234567898.txt in which this number is retrieved frm database.
i tried doing something lik,
DataRow dr = ds.Tables[0].Rows[0];
string number = dr[5].ToString();
string path = "C:/"+number+".txt";
TextWriter txt = new StreamWriter(path);
But the error message says this path structure is not supported..
Wat can b done to solve this problem..?
Thanks in advance,
Soumya
Abdollah HassanPosted Dec 21, 2008, 11:25 AM
Hello
i create text file in my computre but after publish web site for create file i have error " acces denide c:\test.txt
soumya p nPosted Jan 9, 2008, 4:49 AM
Blocked AccountPosted Jan 9, 2008, 3:31 AM
This is the working code. I think problem with the path you defining . Put the breakpoint there and check in runtime what path is :
soumya p nPosted Jan 9, 2008, 2:37 AM
i checked with ur code and its still showing the same error which says that,
The given path's format is not supported
Regards,
Soumya
soumya p nPosted Jan 9, 2008, 2:24 AM
soumya p nPosted Jan 9, 2008, 2:23 AM
Blocked AccountPosted Jan 9, 2008, 1:29 AM
Use like that.
public StreamWriter objWriter;
FileStream outputfile = null;
string textPageName=ViewState["FolderPath"].ToString()+ "/";
string textPageName1 = textPageName + MoblieNumber + ".txt";
if (!Directory.Exists(textPageName))
Directory.CreateDirectory(textPageName);
outputfile = new FileStream(textPageName1, FileMode.Create, FileAccess.Write);
objWriter = new StreamWriter(outputfile);
objWriter.Close();
outputfile.Close();
Happy Coding!!
ArshadPosted Jan 9, 2008, 1:25 AM
Hi,this is the code to Write a text file in ur Harddisk
using System;
using System.IO;
class Class
{
static void Main()
{
// Write out to text file
StreamWriter writer = File.CreateText("c:\\me.doc");
writer.WriteLine("Arshad you are Out of file.");
writer.Close();
}
}
But tell me one thing that u r looking for that ur text file name should be come from ur database????????
Is it?????
Regards
Arshad Khan