By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,667 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,667 IT Pros & Developers. It's quick & easy.

Accessing a file on the CD?

P: n/a
I have an application which today loads some XML files onto the hard
drive. We have been acked to change the application to instead keep
the data files on the
CD. I have fixed the install, but now am trying to fix the C# code to
look at the CD instead of the folder on the Hard drive.
Here is the code that exists now.

public String GetApplicationFolder()
{
String sPath = Application.ExecutablePath;

return(sPath.Substring(0,sPath.LastIndexOf("\\")) + "\\");

}

I need it to look at the CD instead of the ExecutablePath. Any help
would be greatly appreciated.
Thanks,
Eric Swaney
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Eric,

If your files have to be read from CD-ROM drive then you can
search for those in this way:

public string GetDocXmlFilePath(string relatedPath) {

string[] drivesPathTab=Directory.GetLogicalDrives();
for(int i=0; i<drivesPathTab.Length; i++) {
DirectoryInfo dirInfo=new DirectoryInfo(drivesPathTab[i]);
if( (dirInfo.Attributes & FileAttributes.ReadOnly)!=0 ) {

// this drive is read only so...
// if you know related path you can acces your file
// after checking if it exists on this drive...

string fullPath=Path.Combine(drivesPathTab[i], relatedPath);
if( File.Exist( fullPath) ) {
return fullPath;
}
}
return String.Empty;
}

Aboved sample should be working, but it is not a "State Of The Art"... (o:

Those sample should help you find a way to minimize searching for wanted CD-ROM
drive... e.g. if path is returned then keed it in variable since file
wasn't found in a path, then search again...
And to avoid of reading floppies (it doesn't "sounds" good).

Marcin Grzębski

Eric wrote:
I have an application which today loads some XML files onto the hard
drive. We have been acked to change the application to instead keep
the data files on the
CD. I have fixed the install, but now am trying to fix the C# code to
look at the CD instead of the folder on the Hard drive.
Here is the code that exists now.

public String GetApplicationFolder()
{
String sPath = Application.ExecutablePath;

return(sPath.Substring(0,sPath.LastIndexOf("\\")) + "\\");

}

I need it to look at the CD instead of the ExecutablePath. Any help
would be greatly appreciated.
Thanks,
Eric Swaney


Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.