|
I just use a FileInfo. Don't try to write your own.
|
|
|
|
|
Nope. FileInfo is not what I wanted. I asked about Directory not file.
I used like This: (From Memory)
String path = "c:\TempCacheFolder";
Directory.CreateDirectory(path);
Directory.RemoveDirectory(path);
I needed to know if imputed string is valid before creating. I am currently designing Cache Engine for my custom control. The property CacheFilePath has get and set property. When someone programaticly enter an invalid area where it can't be written, without actually creating it before it is needed. And there is error within my approach. If I create directory with a path that have more subfolder that doesn't exsist:
Example:
Faze1. Test Create a folder.
C:\MyApp\UnkownFolder\Unkownfolder2\TempImageCache.
Faze2. Remove Folder. (Will remove only TempImageCache)
I wan't to avoid this needless step. I only wan't to validate, that the unknown directory can be created without actually creating before needing.
I am sorry if I was too cryptic about my previous posts
|
|
|
|
|
Saksida Bojan wrote: if imputed string is valid before creating
That's a waste of time -- things can change between the test and the creation.
When it comes time to create, just try to create and report any errors.
|
|
|
|
|
Saksida Bojan wrote: Is there any better check to check if a path inside string is valid? Building on the former posts, you'd like to check whether the parent-path is valid, and whether the name-part of the new folder is valid?
C:\Windows\MyBla:Folder
In order to verify whether "MyBla:Folder" is a valid name?
You could check the parent-path as suggested, but there may be a *lot* more reasons why the creation of a folder might fail. Don't forget your try-except I are Troll
|
|
|
|
|
I used like This: (From Memory)
String path = "c:\TempCacheFolder";
Directory.CreateDirectory(path);
Directory.RemoveDirectory(path);
I needed to know if imputed string is valid before creating. I am currently designing Cache Engine for my custom control. The property CacheFilePath has get and set property. When someone programaticly enter an invalid area where it can't be written, without actually creating it before it is needed. And there is error within my approach. If I create directory with a path that have more subfolder that doesn't exsist:
Example:
Faze1. Test Create a folder.
C:\MyApp\UnkownFolder\Unkownfolder2\TempImageCache.
Faze2. Remove Folder. (Will remove only TempImageCache)
I wan't to avoid this needless step. I only wan't to validate, that the unknown directory can be created without actually creating before needing.
I am sorry if I was too cryptic about my previous posts
Eddy Vluggen wrote: In order to verify whether "MyBla:Folder" is a valid name?
More like if it can create without creating new folder. I am designing custom control (Currently Cache Engine) I intend to handle it without trusting user input. And return errors that the user (developer) can easily repair problem
|
|
|
|
|
In order to determine validity of a path, you should not modify the file system, hence CreateDirectory and RemoveDirectory are not acceptable. Calling them may cause a lot of unwanted side effects, e.g. when a FileSystemWatcher has been installed.
What you can do is:
1. use Path.GetFullPath()
2. use new DirectoryInfo()
each of those will throw an appropriate exception when the path isn't valid.
And of course you could parse the path yourself (not recommended).
|
|
|
|
|
tham. Didn't know DirecotryInfo had such flexebility. thanks. The code so far:
public static bool IsValidPath(String path)
{
DirectoryInfo di;
try
{
di = new DirectoryInfo(path);
}
catch (NotSupportedException) { return false; }
bool foundLogicalDrive = false;
foreach (String str in Directory.GetLogicalDrives())
{
if (path.Substring(0, 3).ToUpper() == str)
foundLogicalDrive = true;
}
if (!foundLogicalDrive)
return false;
return IsValidPathParser(di);
}
private static bool IsValidPathParser(DirectoryInfo di)
{
if (di.Exists)
{
return true;
}
else
{
if (di.Name.ToUpper() != di.Root.Name.ToUpper())
return IsValidPathParser(di.Parent);
else
return false;
}
}
The last part i wan't to check if users have permision to create and write in that folder. So far i haven't found anything usefull. Still googleing about DirectorySecurty.
|
|
|
|
|
I have to agree with the other posters, creating and deleting the dir is at best inelegant.
You may have a valid path, with write permission, but not create permission.
Worst case, I would check it for null, then get info on it from Directory.
If this fails, get rid of everything from the last '/' back, inclusive, and try again.
If that fails you know the proposed directory/file does not exist and that the directory holding also does not exist.
If it succeeds, you would have needed to get file info to determine if you have write or create permissions to the paths given.
We had a sergeant, in officer basic course, when (not if)one of us LTs came with an f'd up way to do something, he'd say:
"it's a technique"Opacity, the new Transparency.
|
|
|
|
|
|
I knot it is possible, because i saw message here and i can't find it.
Whitch atribute i need to set, so that when I double click in Solution explorer opens a code instead Designer mode.
Thank you in advance.
|
|
|
|
|
[System.ComponentModel.DesignerCategory("code")]
Found here[^]
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
|
|
|
|
|
thanks, odd thou i tried like this: "[DesignerCategory("code")] " and didn't work
Thank you for assistance
|
|
|
|
|
No worries
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
|
|
|
|
|
Nah. This[^] looks more trustworthy.
|
|
|
|
|
Ahh, yeah, sorry Luc!
I never trust that SO place anyway!!
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
|
|
|
|
|
I want to Zip Folder and all its contents... can any body suggest me the sample or any link.. I want to do it in C#... Pllease help me out...
Thanks in Advance....
|
|
|
|
|
Try this[^] You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
|
1.21 Gigawatts wrote: Or, a simpler method using GZipStream[^]
That won't make (or read) an actual zip file though, only a gzip file
|
|
|
|
|
Ohh.
Ta
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
|
|
|
|
|
|
I want to Export Registry values. I trid a lot and Googled a lot but no sample came me found... can any body help me rearding this...
|
|
|
|
|
|
sir/madam
hoe to create a listview in C#
|
|
|
|
|
Can you be more specific?. The only answer i can give is Drag and drop ListView into Designer.
|
|
|
|