skip to main
|
skip to sidebar
My experiences in .NET
Thursday, September 6, 2007
Programmatically determine if a File is an assembly
We can take help of System.Reflection.AssemblyName class to determine if a file is an assembly or not.
Call the method
'GetAssemblyName' with the full path & file name. If this statement executes successfully the file is an assembly, if it throws 'BadImageFormatException' the specified file is not an assembly.
GetAssemblyName can also throw an exception if the assembly is already loaded.
class
TestAssembly
{
static
void
Main()
{
try
{
System.Reflection.AssemblyName testAssembly =
System.Reflection.AssemblyName.GetAssemblyName(@
"C:\Bharati\test.dll"
);
System.Console.WriteLine(
"Yes, the file is an Assembly."
);
}
catch
(System.IO.FileNotFoundException e)
{
System.Console.WriteLine(
"The file cannot be found."
);
}
catch
(System.BadImageFormatException e)
{
System.Console.WriteLine(
"The file is not an Assembly."
);
}
catch
(System.IO.FileLoadException e)
{
System.Console.WriteLine(
"The Assembly has already been loaded."
);
}
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
Blog Archive
►
2017
(3)
►
February
(3)
►
2016
(1)
►
April
(1)
►
2013
(1)
►
June
(1)
►
2012
(1)
►
January
(1)
►
2011
(1)
►
March
(1)
►
2010
(1)
►
July
(1)
►
2009
(2)
►
March
(1)
►
February
(1)
►
2008
(6)
►
November
(1)
►
May
(2)
►
April
(3)
▼
2007
(56)
▼
September
(5)
Upload a file in Window application
VB.NET + ASP.NET + Data Grid + V1.x
Calling a DB2 Stored Procedure from .NET
Programmatically determine if a File is an assembly
Dynamically Bind Event Handlers at Run Time in ASP...
►
August
(5)
►
July
(14)
►
June
(5)
►
May
(8)
►
April
(1)
►
March
(18)
Contributors
Bharathi
Kumar
Me
Pals
Kumar
Padmini
Lakshmi
Krishnan
No comments:
Post a Comment