File Upload 2.0 Problem - Able to Write File - Can't Delete or Overwrite File

Hi everyone,

I'm doing a file upload in .net 2.0.  I'm able to upload a file to a directory on my server, however I am not able to delete the file or overwrite it.  I've given my <machine>IUSR account full control to the directory but it still wont let me overwrite a file.  I've read that the FileUpload.SaveAs method will overwrite a file without prompt.  I've tried doing the System.IO.File.Delete() Method also with no luck.

Here's the code:

 

 
protected void uploadbutton_Click(object sender, EventArgs e)
    {
        if (upload.HasFile)
        {
            if(System.IO.File.Exists("C:\\Websites\\Home\\images\\partner\\" + upload.FileName))
            {
                System.IO.File.Delete("C:\\Websites\\Home\\images\\partner\\" + upload.FileName);
            }
            upload.SaveAs("C:\\Websites\\Home\\images\\partner\\" + upload.FileName);
        }
    }

 

and here is the error:

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\Websites\Home\images\partner\slappy.gif' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

 

Thanks for any help!

1
response
8/11/2006 3:47:22 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

2 Replies
1201 Views

Similar Articles

[PageSpeed] 57

upon lookin at my event logs, i see that the NETWORK SERVICE account was the account trying to do delete / modify the file, so I gave the NETWORK SERVICE account modify permissions on the folder.  works fine now.  could anyone tell me if this is a security risk going about it like this?

 

thanks,

RC

0
response
8/11/2006 6:09:04 PM

NETWORK SERVICE is the account used by IIS when using Impersonation. For more information, you can refer to these KB articles:

ASP.NET security overview: http://support.microsoft.com/?id=891028

How To Secure an ASP.NET Application by Using Windows Security:

http://support.microsoft.com/?id=315736

 


Welcome to my SQL/ASPNET forum for Chinese
http://51up.org/bbs/forumdisplay.php?fid=38
0
Iori_Jay
8/14/2006 2:07:48 AM
Reply:

Similar Artilces:

superreview granted: [Bug 342321] nsIncrementalDownload doesn't create 0-sized file when downloading a 0-sized file : [Attachment 226514] Always create/truncate the dest. file during the channel's onS
Darin Fisher (Google) <darin@meer.net> has granted Jeff Walden (remove +bmo to email) <jwalden+bmo@mit.edu>'s request for superreview: Bug 342321: nsIncrementalDownload doesn't create 0-sized file when downloading a 0-sized file https://bugzilla.mozilla.org/show_bug.cgi?id=342321 Attachment 226514: Always create/truncate the dest. file during the channel's onStartRequest https://bugzilla.mozilla.org/attachment.cgi?id=226514&action=edit ...

superreview requested: [Bug 342321] nsIncrementalDownload doesn't create 0-sized file when downloading a 0-sized file : [Attachment 226514] Always create/truncate the dest. file during the channel's o
Jeff Walden (remove +bmo to email) <jwalden+bmo@mit.edu> has asked Darin Fisher (Google) <darin@meer.net> for superreview: Bug 342321: nsIncrementalDownload doesn't create 0-sized file when downloading a 0-sized file https://bugzilla.mozilla.org/show_bug.cgi?id=342321 Attachment 226514: Always create/truncate the dest. file during the channel's onStartRequest https://bugzilla.mozilla.org/attachment.cgi?id=226514&action=edit ...

File Upload Problem
Hi Everyone,I was grateful to be able to download the code for uploading files into a folder from Sreedhar's web page. The code works well, but whenever there is another new file with the same file name being uploaded into the destination folder, the old file will be replaced. I am wondering if there is any way to solve this problem (How about adding a number to the new file's name, e.g. File1.doc, if there is an existing File.doc?) I am an absolute beginner and any help is deeply appreciated.The original code is as follows: <%@ Page Language="VB" MasterPageFile="~/MasterP...

superreview granted: [Bug 363654] .url files opened via File:Open don't open/don't open properly on the 1.8.0 branch : [Attachment 248458] disables .url in file:open
Stuart Morgan <stuart.morgan@alumni.case.edu> has granted Smokey Ardisson (unreliable; no bugmail) <alqahira@ardisson.org>'s request for superreview: Bug 363654: .url files opened via File:Open don't open/don't open properly on the 1.8.0 branch https://bugzilla.mozilla.org/show_bug.cgi?id=363654 Attachment 248458: disables .url in file:open https://bugzilla.mozilla.org/attachment.cgi?id=248458&action=edit ------- Additional Comments from Stuart Morgan <stuart.morgan@alumni.case.edu> Well, that kinda sucks. ...

superreview requested: [Bug 363654] .url files opened via File:Open don't open/don't open properly on the 1.8.0 branch : [Attachment 248458] disables .url in file:open
Smokey Ardisson (unreliable; no bugmail) <alqahira@ardisson.org> has asked Stuart Morgan <stuart.morgan@alumni.case.edu> for superreview: Bug 363654: .url files opened via File:Open don't open/don't open properly on the 1.8.0 branch https://bugzilla.mozilla.org/show_bug.cgi?id=363654 Attachment 248458: disables .url in file:open https://bugzilla.mozilla.org/attachment.cgi?id=248458&action=edit ------- Additional Comments from Smokey Ardisson (unreliable; no bugmail) <alqahira@ardisson.org> Asking for sr on this 7-char patch in case we need to take it ...

Eof of file , file read and file write ! Problem !
Hello All, I want to do 2 things. I have a big file and I want to read file line by line upto last. and side by side i want to write it to new file with some change I am not getiing , in a read , linemode! how i will get End of file and how i will do all this. can you tell me script. I'm not sure I understand your question. From the PowerBuilder Help file, in linemode! FileRead() will return a 0 when it reaches End of File (EOF) so it should be trivial to code? This is just off the cuff but I would imagine it's something like li_Readfile = FileOpen( ...

superreview granted: [Bug 66410] Deleting addressbook should also delete corresponding mab file : [Attachment 171183] Don't always create a database file if one doesn't exist
Scott MacGregor <mscott@mozilla.org> has granted Mark Banner <mark@standard8.demon.co.uk>'s request for superreview: Bug 66410: Deleting addressbook should also delete corresponding mab file https://bugzilla.mozilla.org/show_bug.cgi?id=66410 Attachment 171183: Don't always create a database file if one doesn't exist https://bugzilla.mozilla.org/attachment.cgi?id=171183&action=edit ...

superreview requested: [Bug 66410] Deleting addressbook should also delete corresponding mab file : [Attachment 171183] Don't always create a database file if one doesn't exist
Mark Banner <mark@standard8.demon.co.uk> has asked Scott MacGregor <mscott@mozilla.org> for superreview: Bug 66410: Deleting addressbook should also delete corresponding mab file https://bugzilla.mozilla.org/show_bug.cgi?id=66410 Attachment 171183: Don't always create a database file if one doesn't exist https://bugzilla.mozilla.org/attachment.cgi?id=171183&action=edit ...

Files don't upload and File Manager unavailable, permissions ok, path problem
I know what you're going to say: 'Fix the permissions!'. Well those were set just fine. In fact they were so wide open (everyone had full control) that I tightned them down :-) It appears that there is a path problem somewhere: Error: File Manager is currently unavailable. DotNetNuke.Services.Exceptions.ModuleLoadException: Could not find a part of the path "D:\www_virt_dirs\portal\portal\Portals\0\". ---> System.IO.DirectoryNotFoundException: Could not find a part of the path "D:\www_virt_dirs\portal\portal\Portals\0\". at System.IO.__Error.WinIOError(Int3...

Could not load file or assembly 'System.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified
 Hi, I am using Jasper.. I downloaded JASPER and the sample code from http://www.microsoft.com/downloads/details.aspx?FamilyId=471BB3AC-B31A-49CD-A567-F2E286715C8F&displaylang=en but when  i try to run Samples.. I get the error :  Could not load file or assembly 'System.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified i can find only System,Core under 3.5 version. I tried running the project from VS2005 and from VS2008.. still the problem persists....

FTP: Delete File, Move File, Get File Properties (?)
Hi! Using the inet object, how can I (a) Delete an object from the FTP server (b) Move a file from one folder to another on the FTP server (c) Get file properties on a given file (e.g. datetime and size) Thanks! D I think I figured it out..... "Daniel Coppersmith" <daniel@N.0.S.P.A.M_infrontsoftware.com> wrote in message news:#qfwscFpCHA.199@forums.sybase.com... > Hi! > > Using the inet object, how can I > (a) Delete an object from the FTP server > (b) Move a file from one folder to another on the FTP server > ...

upload multi files, then attach file, then delete files help
Hi, I have a web form that needs do three things in one time when user click "submit" button. 1. upload multi files into web server (In know how to do this part) 2. send a email with these uploaded file to another user. 3. delete these uploaded files from web server. I know how to do 1). But, do not know 2) and 3). I know how to send email without attachment, But, once I add attachments. it does not work. Please help. Many thanks. Xiuxain Hi there, Please check the following links.. Sending Attachments and to delete file .. imports sys...

File Upload Doesn't Post the File
First I would like to mention I have known for a long time that a file upload does not work with an asynchronous postback. I've explained that to many people. I have a postback trigger set for the Update panel this is in.My problem is that when I first click the button it does do a full postback, but the file upload control has no file. And my validation catches that and reports the error back. If I then try to upload the file again everything works correctly.Thanks in advance. C. Brendan EnrickBrendan's BlogMake sure you click "Mark as Answer" for any post which has h...

File Upload
Hey I've got a fileUpload control on an aspx page that works fine for the accepted file type, .rpts, and brings up the correct error message for not allowed extensions such as .exes and .jpgs. But .pdf files should cause an error message to be displayed, as only .rpt files are allowed to be uploaded, but instead it brings up a blank page like a web500 page. Is there a known bug when attempting to upload pdf's?   Just in case,here's the only relevant code attached to the control:   If uploadFilename.EndsWith(".rpt") = True Then 'ensures only .rp...

Deleting A File Uploaded Through File Upload Control
Hello, I have a form which allows a user to upload a file to a virtual drive on our server using the following code: fileInvoice.SaveAs(ConfigurationManager.AppSettings.Get("DocumentPath") + strFileName); //Document Path is defined in the web.config file How can I safely allow a form on a web page to delete the file if they know the exact name of the file. I don't want them to be able to do a wildcard match like test* thanks in advance, mitch  Peace be on you brother, so you want to safely delete the file which the name you know. OK I consider that the name ...

Web resources about - File Upload 2.0 Problem - Able to Write File - Can't Delete or Overwrite File - asp.net.getting-started

Resources last updated: 12/28/2015 1:46:16 AM