File.Exist(...) method returns false

869 Views Asked by At

I'm currently working on this .Net/WPF project.

I'm trying to get the method to check to see if a skin file exists before applying. I have feeling that my address formatting my be wrong... Any ideas?

Dim lobjSPEConfigService As SPEConfigurationService = New SPEConfigurationService
Dim lobjSkinFilePath As String = CStr(lobjSPEConfigService.GetApplicationSetting("SkinFileLocation", GetType(String)))

If String.IsNullOrEmpty(lobjSkinFilePath) Then
    lobjSkinFilePath = "/SPE.Infrastructure.UI/Application/Resources/Skins/LightSkin"
Else
    Dim lblnFileExist = File.Exists(lobjSkinFilePath)
    If lblnFileExist = False Then
        lobjSkinFilePath = "/SPE.Infrastructure/SPE.Infrastructure.UI/Application/Resources/Skins/LightSkin"
    End If
End If

The file is being referenced thourg the project...

2

There are 2 best solutions below

1
On BEST ANSWER

If your file name and path correct (not sure I do not see your project) then the only thing I see missing is the file extension. I'm assuming it's .xaml

If you're loading anything as a resource you have to use WPF Pack URI's.

Some examples:

Absolute Path

"pack://application:,,,/ResourceFile.xaml"
"pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml"

Relative Path

"/ResourceFile.xaml"
"/ReferencedAssembly;component/ResourceFile.xaml" 

Also get rid of your first else statement...you're not doing anything once you change the filename if its empty.

2
On

File.Exists() searches on disk. If it returns False the file doesn't exist on disk.

Where File.Exists is looking depends on CStr(lobjSPEConfigService.GetApplicationSetting("SkinFileLocation", GetType(String)))

Check the value in the config file.

Make sure that path does exist and the application has sufficient rights to access/find it.

EDIT

To find an internal (assemly) resource use the ResourceManager