Total VB.Net newbie - Directory.Exists question

  • Thread starter Thread starter ginolard
  • Start date Start date
G

ginolard

Dim b As Boolean
b = System.IO.Directory.Exists("c:\temp")
MsgBox(b)

Could someone explain why that returns FALSE when c:\temp quite
evidently exists?
 
Works here. What if you try to perform some oprations on this dir ? (such as
counting files, writing down a file or reading a file) ?
 
Odd. in Visual Studio 2005 Express this code returns FALSE. In the
full version of Visual Studio 2005 it returns TRUE.
 
Bizarrely, if I try to use fileContents =
System.IO.File.ReadAllText("C:\temp\input.txt") I get a "Security
error" with the following message

Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.

Again, that's odd as I'm admin of my machine and the directory has Full
Control for Everyone.
 
What, Visual Studio 2005 Express itself or my project? I presume I can
also do this via the .Net 2.0 Config Utility wizard (although how is
another matter entirely)
 
Your application. The .NET Framework handles Code Access Security i.e. the
code is not allowed to perform necessarery all actions in particular
depending on its location. In VS 2005, you should have a dialog to do that
automatically when you build...
 
Hmm. When I select Build Application it just completes with a Build
Succeeded message. Sorry for asking what are probably totally dumb
questions but I only installed VS 2005 Express yesterday and started
playing with it today ;)
 
In "Project properties" do you have a "Security" tab ? (translated from
French). It allows to tell which security should be applied to the ClickOnce
application.

If you don't have this in Express, you could configure manually using the
control panel applet. The applet allows to create an MSI file to install
this same policy on other PCs.

The big picture may help (for example instead of dealing with c:\temp the
application could perhaps use the "isolated storage")
 
Sigh....how simple was that in the end? Yes, there is a security tab
and I enabled Clickonce Security Settings and set FileIOPermission to
Include. Sure enough, all now works as expected.

Thank you for your help and patience.
 
Back
Top