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
-1
MitchDW
9/6/2008 12:53:08 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

3 Replies
1065 Views

Similar Articles

[PageSpeed] 11

 Peace be on you brother,

so you want to safely delete the file which the name you know.
OK I consider that the name is comming from a dynamic source such as ConfigurationManager.AppSettings.Get("DocumentPath") + strFileName
right .. now let see the following code

 

 

string filename = ConfigurationManager.AppSettings.Get("DocumentPath") + strFileName;
            if (File.Exists(Server.MapPath(filename)))
            {
                File.Delete(Server.MapPath(filename));
            }
 
 
cheers 
  
Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
http://www.aghausman.net
-1
aghausman12
9/6/2008 1:48:10 PM

Hi

try this method to delete uplaoded file from Album folder in root of website

just give it name of file

public void DeletePysicalFiles(string Name)
    {

        System.IO.FileInfo fi = new FileInfo(Request.PhysicalApplicationPath + "Album\\" + Name);
        fi.Delete();

    }

Good Luck

1
yasserzaid
9/6/2008 5:49:12 PM
Thanks. That did the trick.

--mitch
0
MitchDW
9/6/2008 11:16:03 PM
Reply:

Similar Artilces:

How Do I Enable A File Upload Control When Another File Upload Control Has A Value?
Hi There,Thanks you for taking the time to read this post.  I am quite new to programming and have searched the net and experimented with my own code but not been able to get it to work yet.I am creating a simple CMS for a friends site and my friend wants to be able to upload 9 images per page.I have created an asp.net form with 9 file upload controls.  I want 1 control to be enabled by default and the other 8 controls disabled until the previous control has a value.  I have set the default setting in visual studio without any problem.My first thought was to double cli...

Posting filepath in file upload control in .NET to the next page and uploading the file from second page
In our application (using C# .NET) there is a form with file upload options. After filling up the form details, the summary of the details need to be shown in the next page before committing the information into the database. Right now, Server.Control is used to transfer the contents to the next page and the form details are retrieved using Request.Form["control id"]. But this is not working for File upload control alone.File upload can not be done in the first page itself, as the foreign key in File upload table gets updated only in second page after confirmation. Therefore, is th...

Upload all files in folder with file upload control
H i I'm trying to upload all files to a wesite that is in a specific local folder. My code workes fine when I run it locally but when I upload it it fails. I think it looks for the files to upload on the web server and thus cannot find it.  1 Dim files() As String 2 folderExists = System.IO.Directory.Exists(foldername) 3 If folderExists = False Then 4 Label1.Text = "Folder does not exist. Did you enter a folder name or just a file name ?" 5 Exit sub 6 End If 7 files = System.IO.Directory.GetFiles(foldername) 8 For...

How to identify the original file type and restrict the file uploading while using file upload control
 Hi asp.net , I am uploading a file using FileUpload control in asp.net using vb.net.I wrote the code to upload only PDF files. the user can change the extension and change to PDF . I have to check is the file original PDF or not then i have to upload the PDF files only . How to do this ??  Hi, Check the file Mime type for "application/pdf" by looking at the:  FileUpload1.PostedFile.ContentType RegardsSmcoxonNo Gem is ever polished without some friction. Hi smcoxon , Thanks For Replying ,But i found that there is no use using PostedFil...

How much size of file can be uploaded with file upload control
How much size of file can be uploaded with file upload control? By default its 4mb but it can be chaged through web config settingsAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved. For a detailed explanation on your query have a look into this article http://msdn2.microsoft.com/en-us/library/e1f13641(vs.71).aspxAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point...

Is there any limitation of file types that file upload control can be used to upload?
I am working on a content management system which requires me to upload WebEx recording files (.wrf) through file upload control. But I am getting "internet explorer cannot display the webpage" error. It worked with other files types as txt, doc, xls, pdf, jpg, gif etc. Is it related to any security issue or just a bug with the file upload control?  Thank you. The file upload control doesn't have any file type limitations that I'm aware of, but it does have some size constraints.  By default, ASP.NET is configured to not accept any file's larger than 4...

Add link buttons to each file uploaded using File upload control
Hi,   In my application I have one file upload control. When the user selectes a file to upload and when he clicks on Attach button I need to show him the file name of the file he selected to upload and also show the Remove link button after the file name. In this case I need to generate link button dynamically. I wrote a code like the following:protected void btnAttach_ServerClick(object sender, EventArgs e) {string strFileName = MyFile.PostedFile.FileName;string c = System.IO.Path.GetFileName(strFileName); listBoxAttachedFiles.Items.Add(c);LinkButton b = new LinkButton(); b.Te...

How to upload an Outlook Message in File Upload control in .Net
Hi All, Is it possible to upload an outlook message from outlook in File Upload control.Please don't suggest to save the message onto the desktop and then upload it!   What I am after is really navigating to the outlook folders through the File Upload control and upload a message.  Thanks guys   If there is a way to do it, but it could be used to maliciously read someone's email folders, forgive me if I hope no one answers you. :)...

File Upload control-Control file size
I am using a file upload tool. I believe the default permissible size for a file uploaded through this tool is around 4 mb. How do I change this limit? I don't want it to be changed for all upload controls on the page. I just want it to be changed for one particular control which uploads music. I want to raise the uploaded file size limit for music to 10MB. hi, here are some information for you to refer to, http://www.vikramlakhotia.com/Dealing_With_the_ASPNet_Upload_File_Size_Problem.aspx http://fileup.softartisans.com/fileup-242.aspx http://www.codeproject.com/useritems/AJAXUpload.as...

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server.http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspxPlease Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.comhttp://www.mitatdotnet.blogspot.com As always there are many ways and which ...

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...

To increase file size upload option of a html file upload control in 1.1
Hi, whenever i try uploading files greater than 15kb or so, my file control fails. But smaller files are easily uploaded. Please helpIf you keep your feet firmly on the ground, you'll have trouble putting on your pants! Hi, the default maximum upload size of the total form data, so not only your fileupload, is limited to 4Mb. You can increase that number by overriding the default settings in the web.config. Alter the <httpRuntime maxRequestLength="" /> attribute. Dealing with the maximum upload size of ASP.NET. Grz, Kris.Read my blog. Handy Firefox plugins for web ...

how to get author from file when upload using upload control using javascript
function CheckSchemaFileExistence() { var Schemafilename=document.getElementById('<%= this.flUploadB.ClientID %>').value;if(Schemafilename.length>0) {return true; } else { alert("File Name cannot be empty");return false; } }   we written code in button click . i need a file author name . how to find it can any tell me . thanks in advance Hi harish448 For your information, I know you want to get the file's author name, which from client-side But I think Not all type of files have the attribute of "author name" (I think on...

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...

Web resources about - Deleting A File Uploaded Through File Upload Control - asp.net.getting-started

Deleting Online Predators Act of 2006 - Wikipedia, the free encyclopedia
( DOPA ) is a bill ( H.R. 5319 ) brought before the United States House of Representatives on May 9, 2006 by Republican Pennsylvania Representative ...

Facebook Deleting Inflammatory Content In India
Facebook has been complying with a request by the government of India and removing “inflammatory and hateful content” that has caused tens of ...

Deleting your Facebook page is foolish
... brag, trailing closely behind that fantastically annoying “I don’t even have a TV , never mind watch the drivel!” Let’s lay it out: deleting ...

AdWords Campaign Experiments: Applying or deleting your experimental changes - YouTube
To improve your AdWords experience, we're testing a new tool that helps you optimize your account. AdWords Campaign Experiments, or ACE, does ...

Deleting abusive online content a 'near impossible' task
POSTING offensive, harassing, intimidating or defamatory content online takes mere seconds, but getting it removed can take what feels like a ...

Paleo advocate Pete Evans accused of deleting critical posts on Facebook
Is Paleo Pete Evans is open to dietary debate? Some say he's not.

Microsoft on the threshold of deleting 'appalling' Windows 8 software
MICROSOFT plans to cut its losses on Windows 8, the latest version of the software that runs the majority of the world's computers, jettisoning ...

How to get iOS 8 without deleting everything on your phone
If you've tried downloading iOS 8, or know anyone who has already done so, you're probably familiar with the biggest complaint: The download ...

Dalton McGuinty staffers broke law by deleting gas plant emails
Senior staff members in the offices of both the Ontario energy minister and former premier Dalton McGuinty intentionally deleted emails about ...

Baidu staff, web censor profited by deleting unfavorable posts
Baidu staff, web censor profited by deleting unfavorable posts

Resources last updated: 11/27/2015 6:19:26 AM