473,407 Members | 2,359 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,407 software developers and data experts.

File deletion from server folder

I'm building a site using VS 2005, Expression, vb.net & asp.net 2.0

I want people to be able to upload text & photos - Accomplished!
I want people to be able to edit / delete text on the database - Acomplished!
I want people to be able to delete their uploaded photos from the file
system - Problem!

How do I go about deleting the photo someone has uploaded to a folder?
Say the actual file on the server is: ~/images/picture1.jpg

What i want to do is when someone deletes their entry on the database the
associated photo is also deleted from the file system.
(The database holds the image url in the following format:
~/images/imagename.jpg)

Any pointers would greatly appreciated!

Apr 4 '07 #1
9 3197
You didn't actually specify what your problem is.
Obviously you'd use the System.IO.File.Delete method.
I bet your problem is with permissions though.
You may need to adjust the security on that folder to allow the ASPNET (or
NetworkService) user delete permissions.
Alternately you could use impersonation to have ASP.NET run under a
different user account:
<!-- Web.config file. -->
<identity impersonate="true" userName="Redmond\BillG" password="Melinda"/>

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

"James Page" <Ja*******@discussions.microsoft.comwrote in message
news:73**********************************@microsof t.com...
I'm building a site using VS 2005, Expression, vb.net & asp.net 2.0

I want people to be able to upload text & photos - Accomplished!
I want people to be able to edit / delete text on the database -
Acomplished!
I want people to be able to delete their uploaded photos from the file
system - Problem!

How do I go about deleting the photo someone has uploaded to a folder?
Say the actual file on the server is: ~/images/picture1.jpg

What i want to do is when someone deletes their entry on the database the
associated photo is also deleted from the file system.
(The database holds the image url in the following format:
~/images/imagename.jpg)

Any pointers would greatly appreciated!
Apr 4 '07 #2
Thanks Steve

I'll play around with the system.IO.file.delete method and permissions and
see what i come up with.

If I get in to problems I'll re-post.

Thanks again

JP

Apr 4 '07 #3
On Apr 4, 7:08 pm, James Page <JamesP...@discussions.microsoft.com>
wrote:
How do I go about deleting the photo someone has uploaded to a folder?
Say the actual file on the server is: ~/images/picture1.jpg
string filename = "~/images/picture1.jpg";
File.Delete(Server.MapPath(filename));

Apr 4 '07 #4
Alexey Smirnov wrote:
On Apr 4, 7:08 pm, James Page <JamesP...@discussions.microsoft.com>
wrote:
>How do I go about deleting the photo someone has uploaded to a folder?
Say the actual file on the server is: ~/images/picture1.jpg

string filename = "~/images/picture1.jpg";
File.Delete(Server.MapPath(filename));
Thanks Alexey

What sort of contect would you use this?
Apr 4 '07 #5
Thanks Alexey

Could you perhaps show me the context of your code say in a buttons click
event?

Cheers

James

"Alexey Smirnov" wrote:
On Apr 4, 7:08 pm, James Page <JamesP...@discussions.microsoft.com>
wrote:
How do I go about deleting the photo someone has uploaded to a folder?
Say the actual file on the server is: ~/images/picture1.jpg

string filename = "~/images/picture1.jpg";
File.Delete(Server.MapPath(filename));

Apr 4 '07 #6
On Apr 5, 1:02 am, James Page <JamesP...@discussions.microsoft.com>
wrote:
Thanks Alexey

Could you perhaps show me the context of your code say in a buttons click
event?
I think it can be similar to the following:

void DeleteButton_Click(object sender, EventArgs e)
{
//someone deletes their entry on the database
//let us assume that you have a userid UID
//find picture name

string sql1="SELECT picture FROM users WHERE userid=" +
UID.ToString();
.....

string filename = ... // result of sql-query
File.Delete(Server.MapPath(filename));

//delete user record
string sql2="DELETE FROM users WHERE userid=" + UID.ToString();
.....
}

File is from the System.IO

Apr 4 '07 #7
Alexey Smirnov wrote:
On Apr 5, 1:02 am, James Page <JamesP...@discussions.microsoft.com>
wrote:
>Thanks Alexey

Could you perhaps show me the context of your code say in a buttons click
event?

I think it can be similar to the following:

void DeleteButton_Click(object sender, EventArgs e)
{
//someone deletes their entry on the database
//let us assume that you have a userid UID
//find picture name

string sql1="SELECT picture FROM users WHERE userid=" +
UID.ToString();
....

string filename = ... // result of sql-query
File.Delete(Server.MapPath(filename));

//delete user record
string sql2="DELETE FROM users WHERE userid=" + UID.ToString();
....
}

File is from the System.IO
Thanks again Alexey

Do you have a VB.net example?
Apr 5 '07 #8
On Apr 5, 2:38 am, James Page <f...@rocketmail.comwrote:
Alexey Smirnov wrote:
On Apr 5, 1:02 am, James Page <JamesP...@discussions.microsoft.com>
wrote:
Thanks Alexey
Could you perhaps show me the context of your code say in a buttons click
event?
I think it can be similar to the following:
void DeleteButton_Click(object sender, EventArgs e)
{
//someone deletes their entry on the database
//let us assume that you have a userid UID
//find picture name
string sql1="SELECT picture FROM users WHERE userid=" +
UID.ToString();
....
string filename = ... // result of sql-query
File.Delete(Server.MapPath(filename));
//delete user record
string sql2="DELETE FROM users WHERE userid=" + UID.ToString();
....
}
File is from the System.IO

Thanks again Alexey

Do you have a VB.net example?- Hide quoted text -

- Show quoted text -
There is no big difference between C# and VB

Sub DeleteButton_Click(ByVal sender As Object, ByVal e As EventArgs)

Dim filename As String = ...
File.Delete(Server.MapPath(filename))

End Sub

http://www.developerfusion.co.uk/uti...sharptovb.aspx

:-)

Apr 5 '07 #9
Alexey Smirnov wrote:
On Apr 5, 2:38 am, James Page <f...@rocketmail.comwrote:
>Alexey Smirnov wrote:
>>On Apr 5, 1:02 am, James Page <JamesP...@discussions.microsoft.com>
wrote:
Thanks Alexey
Could you perhaps show me the context of your code say in a buttons click
event?
I think it can be similar to the following:
void DeleteButton_Click(object sender, EventArgs e)
{
//someone deletes their entry on the database
//let us assume that you have a userid UID
//find picture name
string sql1="SELECT picture FROM users WHERE userid=" +
UID.ToString();
....
string filename = ... // result of sql-query
File.Delete(Server.MapPath(filename));
//delete user record
string sql2="DELETE FROM users WHERE userid=" + UID.ToString();
....
}
File is from the System.IO
Thanks again Alexey

Do you have a VB.net example?- Hide quoted text -

- Show quoted text -

There is no big difference between C# and VB

Sub DeleteButton_Click(ByVal sender As Object, ByVal e As EventArgs)

Dim filename As String = ...
File.Delete(Server.MapPath(filename))

End Sub

http://www.developerfusion.co.uk/uti...sharptovb.aspx

:-)
Thanks again Alexey

If I get into problems I'll re-post
Apr 5 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
5
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up...
7
by: Diggler | last post by:
I have a web application that allows a user to manage files on the server. On the page is a counter that tells them how many files are in their folder. When you delete a file from the folder using...
5
by: BlueFrog | last post by:
Hi all, I'd appreciate some ideas on this as I've just spent the last 2 hours trying to solve it to no avail. I'm am building a web application which includes the functionality to upload...
3
by: Joe | last post by:
Hi, I have written a webpage that allows a user to delete files in asp.net with I am having a small problem. To access this page a user has to login via login.aspx page. After successful...
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,...
1
by: pamela fluente | last post by:
Is there an option to avoid the deletion of the entire site when doing the deployment (Publish feature) ? Why on the heart it has to erase *everything* by default? This seems absurd! If am I...
1
roswara
by: roswara | last post by:
Dear all, Currently, I am working on a project to make a web-based application using ASP 2.0 and C#. This application will ask user to input for an excel file which has graphs in it. Then the...
0
by: itshibu | last post by:
I tried to write a program that can open files from the server. But the shared folder in the Win2003 server is password protected. i tried the following code ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.