Accessing a file on the CD?

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

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
 
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);
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, 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
 
Back
Top