Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a logFile and a directory/file that stores objects that my application has serialized within my application's directory. How do I go about this? I know how to create directories and files but I want to create a subDirectory within my applications parent directory. Example: what I've been doing for testing purposes is I'll create a directory; string dir = "C:\MyDir\..."; Directory.Create(dir)... and I store whatever info in this directory that's relevant to my app, but I want to create a "internal" directory to store all of my apps relevant info and not create a external directory on the user's hardDrive...
Posted
Updated 14-Mar-12 18:12pm
v2
Comments
Tejas Vaishnav 15-Mar-12 0:42am    
will you elaborate what meaning for internal directory you meant.?
d.allen101 15-Mar-12 0:45am    
I'm currently creating a directory to i.e. C:\MyDir\...I want to store whatever info is relevant to my application in the same directory that my application resides in. I don't want to create an additional directory on the user's hardDrive...

IsolatedStorage is the solution for your question.

With isolated storage, data is always isolated by user and by assembly. Credentials such as the origin or the strong name of the assembly determine assembly identity. Data can also be isolated by application domain, using similar credentials.

Here is the sample code to store the content in an IsolatedStorage file.

C#
using System.IO;
using System.IO.IsolatedStorage;

const string ISOLATED_FILE_NAME = "MyIsolatedFile.txt";
IsolatedStorageFile isoStore = 
  IsolatedStorageFile.GetStore( IsolatedStorageScope.User 
  | IsolatedStorageScope.Assembly, null, null );

IsolatedStorageFileStream oStream = 
  new IsolatedStorageFileStream( ISOLATED_FILE_NAME, 
  FileMode.Create, isoStore );

StreamWriter writer = new StreamWriter( oStream );
writer.WriteLine( "This is my first line in the isolated storage file." );
writer.WriteLine( "This is second line." );
writer.Close();
 
Share this answer
 
C#
string MyFileName = "MyFile.txt";
string MyLogPathName = "MyLog";
//application BasePath ex:D:\MyApp
string MyAppPath = System.AppDomain.CurrentDomain.BaseDirectory;

// D:\MyApp\MyLog
string MyLogPath = System.IO.Path.Combine(MyAppPath, MyLogPathName);

// D:\MyApp\MyFile.txt
string RelFilePath = System.IO.Path.Combine(MyAppPath, MyFileName);

// D:\MyApp\MyLog\MyFile.txt
string logFilePath = System.IO.Path.Combine(MyLogPath, MyFileName);
 
Share this answer
 
Its a not a big issue. You should code for create directory on anywhere it depends on your path, which you want!
Note that if you want to create Dir on server then you need valid permission like read/write/execute on the server.
 
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