jackjohnson44
asked on
c# can you write to a file if the path you give does not exist?
Is there a way to write to a file, creating the path if it does not exist?
say I want to write to c:\program files\mydir\mydir2\test.tx t
1. is there a way to just specify that path and have the code create it if it doesn't exist?
2. if not, how can I create the path, but only if it does not exist?
say I want to write to c:\program files\mydir\mydir2\test.tx
1. is there a way to just specify that path and have the code create it if it doesn't exist?
2. if not, how can I create the path, but only if it does not exist?
FileStream fs = new FileStream("file and pathname here", FileMode.OpenOrCreate, FileAccess.ReadWrite);
Some More link:
http://www.csharphelp.com/ archives/a rchive24.h tml
http://www.devhood.com/Tut orials/tut orial_deta ils.aspx?t utorial_id =400
I hope you will find good stuff for file operation in above three link. Please let me know if you have any question regarding these link.
Thanks
Ganesh
http://www.csharphelp.com/
http://www.devhood.com/Tut
I hope you will find good stuff for file operation in above three link. Please let me know if you have any question regarding these link.
Thanks
Ganesh
ASKER
Thanks guys, but I don't think I made myself clear. The path does not exist and I want to create it without having to do it manually
this works
FileStream fs = new FileStream(@"c:\test.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
this does not, and it is what I am trying to do
FileStream fs = new FileStream(@"c:\thisDirDoe sNotExistY et\MeEithe r\test.txt ", FileMode.OpenOrCreate, FileAccess.ReadWrite);
this works
FileStream fs = new FileStream(@"c:\test.txt",
this does not, and it is what I am trying to do
FileStream fs = new FileStream(@"c:\thisDirDoe
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
For more information about directory operation, you can find very good stuff here
http://www.aspfree.com/c/a /C-Sharp/A -Look-at-C -Sharp-Dir ectory-and -Directory Info-Class es/
http://www.aspfree.com/c/a
http://www.geekpedia.com/t