HowTo: detect if a file exists in the \Windows folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!
I am using CF SP3 and C# for my application. As soon as the application
launches, I perform a check if all the required files exist in the
Application folder. I use:
Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
to get the Application folder.

Now I also want to check some files in the Windows folder on the device. One
of the files I want to look for is "System.Data.SqlClient.dll" but this
appears as "GAC_System.Data.SqlClient_v1_0_5000_0_cneutral_1.dll" in the
Windows folder. Currently I am using:
string windowsFolderpath = @"\windows\";
File.Exists(windowsFolderpath + fileName);

1.Is there a way that I can use wildcards in the filename so that I can look
for "GAC_System.Data.SqlClient*.dll"?
2. What is the significance of the string "_v1_0_5000_0_cneutral_1" in the
filename? Does this ever change or can I assume that it won't change?
3. Is there any other way to find if specific files exist in the windows
folder?

I will appreciate if anyone can suggest something about this or cite some
examples.
Thank you for your time.

Regards,
Raj
 
The name you see is a GAC name. Instead of trying to check for this assembly
by file name, try instead
try
{

Assembly.Load("System.Data.SqlClient, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=969DB8053D3322AC");
MessageBox.Show("Found");
}

catch

{

MessageBox.Show("Not found");
}


A better solution is not to rely on the assembly name but instead use a
type:
bool TestForSqlClient()

{

try

{

TestForSqlClientInternal();

return true;

}

catch

{

return false;

}

}

void TestForSqlClientInternal()

{

Type t = typeof(System.Data.SqlClient.SqlCommand);

}
 
Thank you for responding Alex.
So, if I have to check for other files, for eg System.Data.Common.dll then
will I have to specify separate try-catch blocks or separate types for each
file I am looking for?

Thank you for your time.
Regards,
Raj
 
Let's put it this way. You know the standard framework assemblies are
available, otherwise your app would not have made it to the Main. Your
application makes use of SQL Client. SqlClient is packaged together with
System.Data.Common. If you already test for SqlClient, it means
System.Data.Common is also available.
 
Ah! I get it. We are just trying to be extra careful with the 'checks' so it
is easy for the support to get to the cause of an error. When we deploy the
application with an installer, we do install .NET CF sp3, Sql Client and
Sr_ENU cab files alongwith our application.

Thank you again for your responses Alex.

Regards,
Raj
 
Back
Top