473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Given a System.IO.File get the directory

Hi,
If I have a File("c:\test\subdir\file1.html"), what's the best way to get
the directory of this file, ie 'c:\test\subdir'? Thanks!
Oct 11 '06 #1
6 2531

MessageBox.Show(System.IO.Path.GetDirectoryName("c :\\test\\subdir\\file1.html").ToString());
SoxFan44 wrote:
Hi,
If I have a File("c:\test\subdir\file1.html"), what's the best way to get
the directory of this file, ie 'c:\test\subdir'? Thanks!
Oct 12 '06 #2
System.IO.FileInfo fi = new
System.IO.FileInfo(@"c:\test\subdir\file1.html");
Response.Write(fi.DirectoryName);
On Oct 11, 6:59 pm, "SoxFan44" <sox...@44.netwrote:
Hi,
If I have a File("c:\test\subdir\file1.html"), what's the best way to get
the directory of this file, ie 'c:\test\subdir'? Thanks!
Oct 12 '06 #3
Thanks :)
"ergintiravoglu" <er************@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>
MessageBox.Show(System.IO.Path.GetDirectoryName("c :\\test\\subdir\\file1.html").ToString());
SoxFan44 wrote:
>Hi,
If I have a File("c:\test\subdir\file1.html"), what's the best way to get
the directory of this file, ie 'c:\test\subdir'? Thanks!

Oct 12 '06 #4
i think, it is long way, is it?
Deepak Khanal wrote:
System.IO.FileInfo fi = new
System.IO.FileInfo(@"c:\test\subdir\file1.html");
Response.Write(fi.DirectoryName);
On Oct 11, 6:59 pm, "SoxFan44" <sox...@44.netwrote:
Hi,
If I have a File("c:\test\subdir\file1.html"), what's the best way to get
the directory of this file, ie 'c:\test\subdir'? Thanks!
Oct 12 '06 #5
not at all ::))
SoxFan44 wrote:
Thanks :)
"ergintiravoglu" <er************@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...

MessageBox.Show(System.IO.Path.GetDirectoryName("c :\\test\\subdir\\file1.html").ToString());
SoxFan44 wrote:
Hi,
If I have a File("c:\test\subdir\file1.html"), what's the best way to get
the directory of this file, ie 'c:\test\subdir'? Thanks!
Oct 12 '06 #6
Hi,

there is no way that you can have a File(....) , File does not have a
constructor as all the methods are static

if you have a File.Open( ... ) you will get a FileStream which has a Name
property. Then you can use System.IO.Path.GetDirectoryName to get the name
of the directory
--
Ignacio Machin
machin AT laceupsolutions.com
"SoxFan44" <so****@44.netwrote in message
news:e$**************@TK2MSFTNGP04.phx.gbl...
Hi,
If I have a File("c:\test\subdir\file1.html"), what's the best way to get
the directory of this file, ie 'c:\test\subdir'? Thanks!

Oct 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Morten Overgaard | last post by:
Hi all Is it possible for a .Net app. to intercept the "open" action on files in a given directory. I want to intercept the "open" action and the perhaps direct the client ( the app. which is...
6
by: Pablo | last post by:
Hi, I'm creating an AppDomain and creating an instance of a class. This works fine unless I use caching, which I need to use. The exception that I get is of type "System.IO.FileLoadException"...
2
by: Jack David | last post by:
Using the code below I am able to monitor a single directory for a new file and then kick-off a process to deal with the file. The question is??? How would I modify this code to be able to monitor...
2
by: raj | last post by:
I want to create a new directory in a given path and need to create a file in that new directory. Any ideas?
4
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
2
by: GeorgeB | last post by:
I have built a solution in vb.net with 2 projects the project with the class libraries and the project which consumes them. The class library project references some other libraries(Different Class...
11
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very...
1
by: Timothy | last post by:
Hi All, Please everyone this is my humble request to all of you if you please have idea about my question then please help me with your master ideas. I have requirement that i should either have...
6
by: gunjan29484 | last post by:
Hello, i want to compare the two directory structures and find out if any file or directory is missing in the second directory structure or not. (directory1 is a super set of directory2) I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.