Change download folder [duplicate] - c#

I am trying to create new file in visual studio 2012
fileStream = new FileStream("google_com.txt", FileMode.CreateNew);
But i keep getting this error
Access to the path 'C:\Program Files (x86)\IIS Express\google_com.txt' is denied.
Plz help to fix this poblem.

Solutions:
Put a specific location for google_com.txt file. like C:\google_com.txt. Actually it is not allowing to create the file in default location(inside program files) as it might not have the proper privilege.
If you want to create the file in default location(inside program files) run Visual Studio as Administrator.(R-Click-> Run as Administrator).

Run Visual Studio as Administrator

You can't write to the Program Files folders on Windows Vista or later unless you're running elevated/as an administrator.
You should be writing to the application's App_Data folder if you need to write anywhere. Look into using Server.MapPath().

If this is in a web app, the file will be created in the application's root, which in this case is your iis express directory. Run Visual Studio as Administrator, or change the location of the file by specifying an explicit path.

Official Microsoft response:
Issue occurs because of missing permissions on a local resource that
the ASP.NET application tries to access If you are unable to get a
clear description of the problem because of a custom error message,
run FileMon and reproduce the problem. Stop and save the capture as
FileMon.xls and open the file in Microsoft Excel. On the Data menu,
click Filter, and then click AutoFilter to use the filtering
capabilities of Excel. Now select the drop-down list in column F and
look for "ACCESS DENIED" errors.
A sample FileMon output is shown below. 10381 1:01:11 PM w3wp.exe:2320
OPEN C:\winnt\microsoft.net\framework\v1.1.4322\Temporary ASP.NET
Files\sessiontest\8832e585\275ec327\global.asax.xml ACCESS DENIED NT
AUTHORITY\NETWORK SERVICE As you can see from the filtered results,
we have narrowed down the cause of the problem. FileMon shows that the
NT AUTHORITY\NETWORK SERVICE account is missing NTFS permissions on
the C:\Winnt\Microsoft.net\Framework\v1.1.4322\Temporary ASP.NET Files
folder. This should be straight forward to fix. For more information
about using FileMon to troubleshoot ASP.NET, click the following
article number to view the article in the Microsoft Knowledge Base
https://support.microsoft.com/es-ve/help/910449/troubleshooting-common-permissions-and-security-related-issues-in-asp

Try this:
Server.MapPath("~/ FolderName / google_com.txt ")

Related

How to access permission to files after installation?

Today I finally ended creating my app.
To install app I used "setup project" from Visual Studio 2019 (image of project type). App is written in C# .NET 4.7.2 Framework.
So I added some folders and files (image of files and folders here). So I gave my friend *.msi file, he istalled that and something happened - path access denied.
I was surprised because when I installed, everything worked, but on my friend's PC when app is trying to write something in file, it gives result that it cannot open it (just doesn't have permission).
My friend went to properties of those files and he didn't have writing permissions (image here in polish language). In that picture in Polish, zapis
mean "writing", so here is my question: how to make setup project in Visual Studio which gives permission to folders/files to modify them?
In general apps don't have permission to write files to the program folders without elevated permissions. Most apps should write data to the users %appdata% folder you can access that path in c# using:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Every work on files and folders must be in Users\user folders, in Documents\folder or in the registry. You shouldn't give permissions to the user to modify files on the system or Program Files.
Although windows installer is able to set file permissions, you should not write anything in Program Files. And you should not grant write permissions there due to security considerations and best practices. So, you need to inspect your code and change all places where you are trying to write in a Program Files (or in the folder where your application is placed) to write somewhere else. For example, in the %temp% folder, in the Program Data or in specific folder inside a user's Documents folder or even ask user to specify write location explicitly.

System.Runtime.InteropServices.COMException: Invalid file name in Crystal Report

I am using Visual Studio 2010 with Crystal Report. It is working fine in my local server but on web server, it is giving error :
System.Runtime.InteropServices.COMException: Invalid file name.
I tried many solutions like put .rpt file in any folder and provide that path, give full permission to windows temp folder, enable parent path form IIS etc.
But none of them is working. Please help me to solve this.
My current path :
crystalReport.Load(Server.MapPath("~/PurchaseOrder1.rpt"));
Not a whole answer but I'm too new to SO just to comment. One thing you could try is to download Process Monitor and watch to see where Crystal is trying to load the file from and that may help. Process Monitor will give a lot of output but that can be filtered on, for instance, part of the filename. It may tell you if there is a permissions issue too. I find it very useful for these sort of situations where you can't work out why a file is not found.
My guess is that the culprit may be a trailing / on the Webserver path.
Try using Path.Combine(Server.MapPath("~"), "PurchaseOrder1.rpt");
This should put appropriate / in the path and might fix your issue.
I think that the main difference with local and server environment is IIS root and the virtual directory that your application is located.
I mean, if the file is in the root of the site, you might want to use
crystalReport.Load(Server.MapPath("/PurchaseOrder1.rpt"));
OR you can try putting the rpt file into the same folder with ViewPurchaseOrder.aspx without changing the code
If it doesn't work, if you could share paths (both physical and virtual) we can check further.
*Edit: When using Server.MapPath
/ returns site root
~/ returns root directory of the application
The difference is that if your site is:
http://yoursite.com
And you have an application that's on wwwroot\somedir\app
So in your "app" (http://yoursite.com/somedir/app)
/ should return the root of the site (http://yoursite.com)
~/ should return the root of the application (http://yoursite.com/somedir/)

Unable to create a new web project in Visual Studio 2013

Background:
I am trying to use my office machine, where I have some limited rights, from home. All products are installed through when I was connected with my network drives, where my profile exists.
Now, I am at home where I don't have an access to these network drives.
Problem:
Whenever I am trying to create a project in visual studio I am getting the following errors:
---------------------------
Microsoft Visual Studio
---------------------------
Package 'ProviderPackage' failed to load.
---------------------------
Finding:
After doing some research I found that it is due to IISExpress. I have ensured that from Tools > options > Web project that IIS express is not enabled for all new web project.
I also got an error as:
---------------------------
Microsoft Visual Studio
---------------------------
Configuring IIS Express failed with the following error:
Filename: redirection.config
Error: Cannot read configuration file
---------------------------
Then I realized that may be it is not able to instantiate with IIS. Then I have tried to run an IIS express from the command prompt and I got this error:
C:\Program Files\IIS Express>iisexpress.exe
An error occurred while reading configuration information. Make sure
that the configuration file
\NAUNSW001\MalhAm\IISExpress\config\applicationhost.config exi sts,
it is accessible, and contains valid configuration information.
I don't have an access to the registry where this path might be picked by the IISexpress.
I have tried to execute the IISexpress /path: c:\vs\ it worked.
However, even then also when I am trying to create a new project I got an error as:
---------------------------
Microsoft Visual Studio
---------------------------
Configuring IIS Express failed with the following error:
Filename: redirection.config
Error: Cannot read configuration file
Alright - I am able to find the workaround.
If you find this error coming then probably it is to do with the IISExpress or IIS configuration that you may not be able to control from home.
The workaround that I have found is that:
Create Project,
System will not be able to attach the project, however it has been created. Then browse to that directory where the project has been created, and open the project file in the notepad or any editor.
Make sure that <UseIISExpress>false</UseIISExpress>
Before modifying further in the project file, Create a virtual directory in your IIS and point to the project path.
find <WebProjectProperties> in your project file config.
Define the virtual directory path under IISUrl.
Your config file should look something like this:
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost/YourAppAlias/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
Please use the following path :
Go to MyComputer>Documents>IISExpress>config>applicationhost.config
Right click on applicationhost.config and go to "Properties" option.
Now click advanced button and uncheck Encrypt contain security data.
Hope this will solve your problem...!!! :)
I had the similar issue could not even start a web project in vs 2013.
None of solutions suggested worked
So i tried the following
Gave read & write permission to following folder
C:\Program Files (x86)\IIS Express\config(default installation iisexpress8)
made sure both subfolders schema and template have read & write access
Then went in to schema folder and renamed asp net_schema.xml and ran iisexpress.exe from command prompt.
It started iis express and successfully registered url "xxxx" for site "webisite1" application
After that i quit iisexpress and renamed the schema file again to the old name.
After that i had no issues starting a web project
I found this it in a strange manner!
look for the IIS config file in my case it was.
C:\Users\\OneDrive\Documents\IISExpress
But accidentally my One Drive was paused. So it was able to access that files in the folder below.
C:\Users\\OneDrive\Documents\IISExpress\config
So just make sure IIS has access to configuration files.
open C:\Program Files (x86)\IIS Express\config.
open schema folder and rename ASPNET_schema (e.g ASPNET_schema1)
copy in run and hit enter "C:\Program Files (x86)\IIS Express\iisexpress.exe" /userhome:c:\temp\iisexpress
and you are all done. enjoy

Could not write to output file -- Access is denied

I recently switched computers and copied all my projects over to my new local drive. I reformatted the computer I'm on now so it was pretty much a clean machine. Everything seemed to be working fine, but when I opened one of my projects that I had been running from my old machine, it would no longer compile, and I get the following error message:
Could not write to output file 'c:\Users\user\Documents\Projects\RegressionWeb\OnetouchUpload\obj\debug\OneTouchUpload.dll' -- 'Access is denied.'
I'm getting an error like that for each project I have in my solution. I'm also getting this error:
Unexpected error creating debug information file 'c:\Users\user\documents\projects\RegressionWeb\RegressionWeb\obj\Debug\RegressionWeb.PDB' Access is denied
I've searched high and low, and the only similar issues I could find online related specifically to ASP.NET and IIS, neither of which has anything to do with my project (My projects are class libraries of mostly NUnit tests with some support classes).
I am the administrator on my local machine. I have already taken ownership of every file in the project using takeown /f .\RegressionWeb /r /d y and also tried to ensure that nothing had a status of Read-only, but the following file threw an error when I tried changing the read-only property of it's parent folder:
An error occurred applying attributes to the file:
C:...\Regressionweb.sln.DotSettings.user
Access is denied
Basically this project was working perfectly and had no errors from my old computer. After copying over everything, this DotSettings.user file will not be modified, and Visual Studio can't write to any of the dll files. I'm sure the answer must lie in a Visual Studio setting somewhere. Any and all suggestions would be greatly appreciated.
I think Karl has it right. I had a similar situation once, and what I did was delete the file in question, clean the solution, and then rebuild. If the project needs that file it should recreate it; in my case it didn't need it because it never recreated it, but the project ran just fine.
One other thing I would recommend; you may be selecting the read-only attribute of the parent folder off and selecting this setting to recurse through all sub-folders and files, but that doesn't mean that's what's happening. For all your sub-folders and files (especially the ones that are cropping up as errors) inspect each one individually and make sure the read-only attribute is off.
My money is on your files are read-only. Verify they are read-only and change them or add your files to a source control system and let them get handled by that.
I was able to get this working by closing Visual Studio and then opening it again, but being careful to run Visual Studio "As Administrator". To do this, from the Start menu, right click on Visual Studio and choose "Run as Administrator".
it seems that the same error is sometimes displayed when the app pool user doesn't have access to the %TMP%/%TEMP% folder.
You'll need to grant IIS_IUSRS read and modify access over the temp folder of the user the app pool is running as.
This could either be the temp folder in the app pool user's profile, e.g. c:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp, or the system temp folder at c:\windows\temp.
See if it is related to this:Could not write to output file - Access is denied
. That would be a bit of a bugger to track down. In this case the project is self-referencing the dll and preventing access to the file.
This has a very simple solution, you just have to make sure that your directory name(folder name) is not the same as your file name. I created a folder by the name Pointers, my code was in a file pointers.cpp. When I compiled the code it kept showing the same error. I just had to change the directory or folder name to L1_pointers. You can change it to anything you want and it worked.

Visual Studio Deployment Package Change File Permissions

Maybe this isn't possible due to Security implications...
I have a Deployment Package created in Visual Studio for a Win Form. The application references an app.config file locally and allows the user to change the settings in it, through the application.
When I deploy the application and attempt to save the changes I have made, Windows is saying "Permission denied". Is there a command I can run as part of the installation that will give the "Everyone" security permission to my app.config file....and thus allow my Application to edit it?
Thank you.
If you want to be able to write to the app.config file you need to move it to the Shared Application Data directory and modify your application to read the configuration information from there. On Win7 for example:
C:\ProgramData\YourCompany\YourApp\app.config
In C#, to get the common app data directory:
// using System.IO;
string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
You might be able to use a custom action in your installer to run icacls in order give full access to Everyone:
icacls {Path to App.config} /grant Everyone:(F)

Categories

Resources