Sunday, November 11, 2007

Can You Sleep With Compression Shorts On

The path of the application

Hello I've been looking for ways in which to find the folder for the Implementation ; ny finally found several ways to do

Form 1: Using
Reflection, we find the path of the assembly that is running, but that if you take into account that this works Windows applications, web application returns the path to a temporary, which is not the path where the dll is being

running

Spath = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly.Location)

through the class path only extract the asembly directory run the command running

Form 2:
Spath = System . AppDomain.CurrentDomain.RelativeSearchPath

This method works well in web applications that call for the assembly in which you run the command above, but in windows applications not working, why? .. not yet (maybe after you find out) returns null

Forma3:
Spath = System.AppDomain.CurrentDomain.BaseDirectory
This form has an interesting behavior when an application runs on Windows returns the directory where the DLL is running the method, but when tested in an application n Web or a WebService which returns the Web application root

An application for this could be that bald or want to verify the license of your system and it be read a file that has the license key and is hosted in the folder of the DLL that runs the verification method. For that creeen a method in that DLL something like this:

Public

Shared Function Licenciaválida() As Boolean

Dim sPath As String

sPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)

sPath & = "\MiFile.txt"


If
Not File.Exists(sPath) Then
   
sPath = System.AppDomain.CurrentDomain.RelativeSearchPath
    sPath & = "\MiFile.txt"

    If Not File.Exists(sPath) Then
       
sPath = System.AppDomain.CurrentDomain.BaseDirectory
        sPath & = "\MiFile.txt"

     End If

End If

f =

New StreamReader(sPath)
Dim s_CLave As String = f.ReadLine
f.Close()
f =
Nothing

return VerificarClave( s_Clave)


End Function

That's all for today

Salu2
Sergio

0 comments:

Post a Comment