473,783 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

144 New Member
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\wwwr oot\picture
folder

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

If Not (myfile.PostedF ile Is Nothing) Then

Dim intFileNameLeng th As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String

'Logic to find the FileName (excluding the path)
strFileNamePath = myfile.PostedFi le.FileName
intFileNameLeng th = InStr(1, StrReverse(strF ileNamePath), "\")
strFileNameOnly = Mid(strFileName Path, (Len(strFileNam ePath) - intFileNameLeng th) + 2)
If strFileNameOnly = "" Then
Lab.Text = "You Must Choose a Picture"
Exit Sub
End If
myfile.PostedFi le.SaveAs("c:\i netpub\wwwroot\ Picture\" & 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 1892
shweta123
692 Recognized Expert Contributor
Hi,

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

File.Delete("di rectory 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\wwwr oot\picture
folder

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

If Not (myfile.PostedF ile Is Nothing) Then

Dim intFileNameLeng th As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String

'Logic to find the FileName (excluding the path)
strFileNamePath = myfile.PostedFi le.FileName
intFileNameLeng th = InStr(1, StrReverse(strF ileNamePath), "\")
strFileNameOnly = Mid(strFileName Path, (Len(strFileNam ePath) - intFileNameLeng th) + 2)
If strFileNameOnly = "" Then
Lab.Text = "You Must Choose a Picture"
Exit Sub
End If
myfile.PostedFi le.SaveAs("c:\i netpub\wwwroot\ Picture\" & 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 New Member
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 New Member
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
1836
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 file from the remote site. When I do this, I end up with 0 byte files. I was hoping to avoid parsing a list of remote and local files and matching them up that way because it would be easier to remove on successful retrieve. I'm including some...
1
8905
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 automatically deletes also all those rows in the child table whose foreign key values are equal to the referenced key value in the parent row. However:
2
8807
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 row in the table is deleted. I have been trying to use this command in a trigger (<filename> is the name and path of the file): xp_cmdshell "delete <filename>" If some one could please help I would appreciate it very much. I would love a...
1
1908
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 process cannot access the file ... It is being used by another process". I also get this error when trying to delete through explorer on the server. I can delete the file if I stop the Web Server service... Is there a way around this? Here is the...
6
2586
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 during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.PathTooLongException: The path is too long
0
2851
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 and filename of the file to delete from the request.QueryString("path") so i got the above error when i try to delete the file before upload. Please anyone help me to solve out from this error. <%@ Import Namespace="System.IO" %>
1
2364
by: nasirmajor | last post by:
dear all, Please any urgent help regarding following code. i have the following code ================================================================= public void Delete(Object sender, DataGridCommandEventArgs e) { 1 int Sid2 = (int)l.DataKeys;
3
3282
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 (i.e. the root directory). This is the code: <script runat="server"> Sub MoveFile(ByVal obj As Object, ByVal ea As EventArgs) File.Move(fudFileSource.FileName, txtFileDest.Text) 'File.Move("F:\4.jpg", "C:\4.jpg") End Sub
4
25181
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 Repair on because the LDB file is still present. It tells me it is being used by a user "Admin" on my machine (a fact that is echoed when I open the LDB file in Notepad.) Unfortunately there is no username "Admin" on the network. When I try to...
2
15011
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 using the file (used X because the filename does not matter...it is a specific log file name to the application). I am logged onto a Windows Server 2003 computer that acts as a server for a LAN, but is physically joined to a domain. The local...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.