Discussion:
HowTo: detect if a file exists in the \Windows folder
(too old to reply)
Raj Kumar
2005-02-16 23:27:02 UTC
Permalink
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
Alex Feinman [MVP]
2005-02-17 01:41:15 UTC
Permalink
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);

}
--
Alex Feinman
---
Visit http://www.opennetcf.org
Post by Raj Kumar
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
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
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
Raj Kumar
2005-02-17 18:31:06 UTC
Permalink
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
Post by Alex Feinman [MVP]
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
bool TestForSqlClient()
{
try
{
TestForSqlClientInternal();
return true;
}
catch
{
return false;
}
}
void TestForSqlClientInternal()
{
Type t = typeof(System.Data.SqlClient.SqlCommand);
}
--
Alex Feinman
---
Visit http://www.opennetcf.org
Post by Raj Kumar
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
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
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
Alex Feinman [MVP]
2005-02-17 18:38:46 UTC
Permalink
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.
--
Alex Feinman
---
Visit http://www.opennetcf.org
Post by Raj Kumar
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
Post by Alex Feinman [MVP]
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
bool TestForSqlClient()
{
try
{
TestForSqlClientInternal();
return true;
}
catch
{
return false;
}
}
void TestForSqlClientInternal()
{
Type t = typeof(System.Data.SqlClient.SqlCommand);
}
--
Alex Feinman
---
Visit http://www.opennetcf.org
Post by Raj Kumar
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
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
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
Raj Kumar
2005-02-18 15:25:06 UTC
Permalink
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
Post by Alex Feinman [MVP]
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.
--
Alex Feinman
---
Visit http://www.opennetcf.org
Post by Raj Kumar
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
Post by Alex Feinman [MVP]
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
bool TestForSqlClient()
{
try
{
TestForSqlClientInternal();
return true;
}
catch
{
return false;
}
}
void TestForSqlClientInternal()
{
Type t = typeof(System.Data.SqlClient.SqlCommand);
}
--
Alex Feinman
---
Visit http://www.opennetcf.org
Post by Raj Kumar
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
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
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
Loading...