Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just bought a new computer, and I'm using Windows 7 X64 and Visual Studio 2012. I also just upgraded to Visual Studio 2012 as well.

I have this web project in which I store SMTP stuff in an INI file in the /App_Data Folder, and using debug or F5, I can't read the file. I get the System.Security.SecurityException from the WebDev.

I search around looking for permission settings for the folder, but could not find anything out there.

I'm new to Windows 7, so I could use some help here.

[UPDATE]

The code works fine on the web servers running Server 2012, I just wanted to update the program code fix the java script, and wanted to step through the code to check something on my machine.

Kind of 1 more thing to do with my new Windows 7 install.
Posted
Updated 23-Nov-13 17:56pm
v5
Comments
Richard C Bishop 22-Nov-13 12:42pm    
Why put the file in that folder?
jkirkerx 22-Nov-13 12:54pm    
I ran across that searching the internet for answers. I meant it's a web project, and was referring to the App_Data folder in the web project, not the App_Data folder in the User Folder.

I store it there because I wrote the program years ago in .net 2.0
Richard C Bishop 22-Nov-13 12:58pm    
Forgive me, I was thinking "bin" folder. The App_Data folder is fine. Can you right-click the file and check the properties? The file might be set to readonly.
jkirkerx 22-Nov-13 13:22pm    
Actually everything was read only, I just change that after I replied earlier.

I'm sure it's something stupid, I had the last computer for 7 years.

Right now, I'm messing with this
Dim file_ioPermission = New FileIOPermission(FileIOPermissionAccess.AllAccess, m_appDataPath & "App_Data\smtp\smtpConfig.ini")
file_ioPermission.Assert()

And my friends wondered my I wasn't excited about my new computer!
And I'm the last one to migrate to Windows 7, needed a new computer.

jkirkerx 23-Nov-13 15:02pm    
I got it working now, not sure what fixed it, I edited the question with what I did.
Uninstalled VS 2012, reinstalled and applied a patch. Go Figure, scared to install update 4 again.

1 solution

Well I was able to isolate the problem here.

To read all files in my web projects App_Data Folder, I deleted the project file and made a new project. I was now able to read XML and HTML template files, and write log files.

So Now I still get the System.Security.Principal error reading the INI file. So I changed the trust from medium to full to read my INI file. Now I can read the file, but the GetPrivateProfileString still bombs.

So I changed the way I referenced the Kernel32.dll
<dllimport("kernel32.dll",> _
   Private Shared Function GetPrivateProfileString(
       ByVal lpApplicationName As String,
       ByVal lpKeyName As String,
       ByVal lpDefault As String,
       ByVal lpReturnedString As System.Text.StringBuilder,
       ByVal nSize As Integer,
       ByVal lpFileName As String) As Integer
   End Function

and changed
 intCharCount = GetPrivateProfileString(Section, Key, [Default], objResult, objResult.Capacity, strFilename)
this -> GetString = Left(objResult.ToString, intCharCount)
to this -> GetString = objResult.ToString

Why the Left doesn't work I'm not sure. Guess I can't reference the Microsoft.VisualBasic in the header to use Left in that Library.

There was an article that says instead of using the stringbuilder, I should use a char array, but I wasn't able to figure out how to marshal it in VB.

So it was a combination of things here. It works, but it needs more polishing, I don't want any more problems here in the future. I welcome anyone's 2 cents here.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900