473,378 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to delete a file in web server in ASP.NET

144 100+
Posted Date :- 17 feb 2008

Hello to everybody,
I am very thankful to "the scripts" contributors. Their answers are really useful to me.

Now i have a Question

I am storing a image in webserver normally in c:\inetpub\wwwroot\picture
folder

In case i know how to insert a image in webser.. by the following code.

If Not (myfile.PostedFile Is Nothing) Then

Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String

'Logic to find the FileName (excluding the path)
strFileNamePath = myfile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
If strFileNameOnly = "" Then
Lab.Text = "You Must Choose a Picture"
Exit Sub
End If
myfile.PostedFile.SaveAs("c:\inetpub\wwwroot\Pictu re\" & strFileNameOnly)
path = "http://localhost/Picture/" & strFileNameOnly


End If






But I dont know how to delete a image in the webserver,
if anybody Knows Pl reply to me...

Waiting for Ur Reply........................



Davidson
Feb 17 '08 #1
3 1877
shweta123
692 Expert 512MB
Hi,

You can use the following method to delete the files on the web server :

File.Delete("directory path")

Posted Date :- 17 feb 2008

Hello to everybody,
I am very thankful to "the scripts" contributors. Their answers are really useful to me.

Now i have a Question

I am storing a image in webserver normally in c:\inetpub\wwwroot\picture
folder

In case i know how to insert a image in webser.. by the following code.

If Not (myfile.PostedFile Is Nothing) Then

Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String

'Logic to find the FileName (excluding the path)
strFileNamePath = myfile.PostedFile.FileName
intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
If strFileNameOnly = "" Then
Lab.Text = "You Must Choose a Picture"
Exit Sub
End If
myfile.PostedFile.SaveAs("c:\inetpub\wwwroot\Pictu re\" & strFileNameOnly)
path = "http://localhost/Picture/" & strFileNameOnly


End If






But I dont know how to delete a image in the webserver,
if anybody Knows Pl reply to me...

Waiting for Ur Reply........................



Davidson
Feb 17 '08 #2
davidson1
144 100+
Hai thank U,

when i give file.Delete it is showing error , can U give some detailed code, so that i can try...

Thank U......

Waiting for Ur Reply....

Posted Date :- 18 Feb 2008
Feb 17 '08 #3
davidson1
144 100+
Thank U

System.IO.File.Delete("path")

worked for me...........

Thanks..............
Feb 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Peter A. Schott | last post by:
Got a strange scenario going on here in that I could have sworn this worked yesterday. I am issuing binary retrieval calls to an FTP server, writing to a file, close the file, then removing the...
1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
2
by: Ryan | last post by:
I have a table in my database on SQL Server which holds a file name that refers to a file that is stored on the server. I would like to create a trigger to delete this file from the server if the...
1
by: Matt Hamilton | last post by:
I have a simple image gallery where I want to allow users to delete files. The problem I have is that after an image is displayed in the browser, I am not able to delete the file because "The...
6
by: I am Sam | last post by:
I keep getting this error and I don't know why: The path is too long after being fully qualified. Make sure path is less than 260 characters. Description: An unhandled exception occurred...
0
by: smanisankar | last post by:
hi, the following is the full page code for uploading a file to server. since i got no idea to overwrite the file, i want delete the file if the file is already uploaded. i got the folder name...
1
by: nasirmajor | last post by:
dear all, Please any urgent help regarding following code. i have the following code ================================================================= public void Delete(Object sender,...
3
by: Arpan | last post by:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls. Using the FileUpload control, I want to give users the provision to move & delete files that DO NOT exist in C:\Inetpub\wwwroot...
4
by: Sailor1877 via AccessMonster.com | last post by:
I've been reading all the threads about problems with LDB files but my specific problem doesn't seem to be addressed. I have a back end database on a server that I'm unable to run Compact and...
2
by: SCPOS | last post by:
Cannot delete X: It is being used by another person or program. Close any programs that might be using the file and try again. Of course I have tried closing any programs I know of that may be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.