Solved

Click-Once deployment and System.Io.File.Exists Fails after install

Posted on 2012-04-04
8
524 Views
Last Modified: 2012-05-31
Hi!

could somebody tell me why this works fine when debugging but fails after i install the Click-once application. i don't get any error messages and the application keeps
running but all file.exists calls just doesn't work. Trust issue ? (visual studio 2008)

if File.Exists("C:\Documents and Settings\All Users\Documents\images\testimage.jpg") Then
......
0
Comment
Question by:jamppi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37809948
what error do you get?
0
 

Author Comment

by:jamppi
ID: 37810235
I dont get any errors,  the code is not executed. but other parts of the solution runs fine.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37810284
Try using the standard folder path for MyDocumets e.g
Dim ThePath = Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "images\testimage.jpg")
If File.Exists(ThePath) Then
    'do yo thang!
End If

Open in new window

0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 40
ID: 37814409
nepaluz gave what could be the right solution, but did not say why you should use that technique.

Many standard directories are not so standard. They change name between operating systems and/or operating system languages. Documents and Settings has been replaced by Users in Windows Vista. It is called Utilisateurs on a French installation of Windows.

The technique given by nepaluz simply retrieve the name of the directory as it exists on the computer on which the code is running. You should always use that technique when you reference one of the standard directories, such as My Documents, My Music, Windows, System, etc.
0
 

Author Comment

by:jamppi
ID: 37817345
Hi!

I will test that!
But it doesn't answer why it works when i debug but not when i deploy it!
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37817393
File.Exists() returns a Boolean (True or False), so the patently obvious reason is that it has returned a False (and that the file does not exist!).
However, since it does return a true while in debug mode suggests that the file actually exists, and you are right to assume it should return a true after compilation.
I suggested you use the standard naming used by the framework to help narrow down the cause of this anomally. What is clear is that at runtime outside the debuger it returns a false, so it is over to you!
0
 

Author Comment

by:jamppi
ID: 37861535
Hi!


I'm still having the same issue.

Btw.  My.Computer.FileSystem.SpecialDirectories.MyDocuments  gives the path to \userxxxxx\Mydocuments.

i need to get to 'All Users\Documents'    (XP)  or ' C:\Users\Public\Documents\'  (win7)
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 37861625
For all users' documents use
Dim ThePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "images\testimage.jpg")
If File.Exists(ThePath) Then
    'do yo thang!
End If

Open in new window

0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question