Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The Pains Of Directory.Delete 1

Status
Not open for further replies.

MarkZK

Technical User
Jul 13, 2006
202
GB
Hi all,

I'm having issues deleting folders with ASP.NET VB, whenever I delete a folder using "Directory.Delete", it clears all of my sessions, as stated here ... FOUR! years ago.

I did a search at tektips, but the post I found was closed,

I have tried ca8msm's suggestion by moving the folder out side of the project folder,

So, try having your site at:

c:\inetpub\
and your files somewhere else e.g.

c:\inetpub\

But even after moving the folders and files saved/deleted to a folder out side of the project folder it STILL clears my sessions, is this normal ? or has anyone actually managed to get this to work ?, it's starting to drive me a little mental considering this would be so easy to do in classic asp, without all this asp.net restart nosense.

Another solution seems to be using linkd

But, I can't access the server to install anything, so not an option for me :(

Also I read the out-of-process would keep my sessions,

Yet again this means having access to the server to edit the services.msc, not an option AGAIN....

I'm wondering if opening a classic asp page with FSO to delete the folder(s) (as mad as that sounds), but that might still clear my sessions because a change was made AND I really shouldn't have too!!!.

If anyone can help that would be great, ANY ideas are welcome, THANKS!!..
 
why are you allowing clients to modify the server's directory structure? this seems like a rather large security risk.

instead of deleting the entire directory, delete the files within the directory.
Code:
foreach(var file in Directory.GetFiles(path))
{
   File.Delete(file);
}
or
Code:
var directory = new DirectoryInfo(path);
foreach(var file in directory.GetFiles())
{
   file.Delete();
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Hi JMeckley,

Thanks for the reply and the code, I'm only allowing them to delete the folders that they create and as far as security goes, it is only the "myfiles" (using ca8msm's example) folder that has modify permissions set, so at the very worst only that folder could be "messed with", right ?.

The problem with not deleting the folders is that that means either they will end up with a bunch of empty old folders on the server or I'd have to restrict them to a set of pre-named folders ?, either way doesn't sound good.

The real issue is the fact that the sessions aren't held (or that the app restarts when a folder is deleted).

Also, ThatRickGuy stated in the tektip thread that 15 files being deleted will do the same thing, I haven't tested that yet, but if it is the case I'll be back at square one.


Thanks again :)
 
could you save the files in the database rather than on the machine? this would eliminate the deleting issue, now it's just a record in the table. not directory or permissions issues to deal with.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
I was just looking into the mode="SQLServer" option, which seemed like a perfect answer to the problem, until I received an error back from MS SQL : "SQLServerAgent is not currently running so it cannot be notified of this action.".

The server in one way or another just keeps failing me.

Yeah, I'm actually using a DB for displaying the file/folder structure and to list all the folders and files, but when I thought about having one folder with all the files in it I thought about the file names having to be unique, also I've set the database up so that they can have a main directory with two-deep sub-folders, so even if I was to prefix the file name with the folders names at 15 max characters in length it could possibly be 45 characters of folder name (three folders deep) before you even set a file name, I guess I just liked the idea of folders and short file names that could be repeated in different folders.

I know exactly what you're saying though and I have no doubt that you're right and that is the safer/better way to go, I'm just moaning because I code it all by hand to keep it valid and semantic and it feels like I'm going to have to re-think and redo about 50% of the app, it's days like this I wonder about PHP and what I'm missing :D, oh well, I'll stop moaning now,

Thanks again JMeckley :)
 
if you're application is managing the files then files names should not be an issue. name them with a GUID and save the friendly name in the database. the user will see "Pic of Me.jpg" but the applications sees 6FJR5KRIF7FY4GRMRKF8D6D.JPG.

if you use the database to store the files then it's an ID to delete a record. to view the images use a generic handler (ashx) to load the image from the database. plenty of examples online.
it feels like I'm going to have to re-think and redo about 50% of the app
well, once you finish updating the application I would recommend researching the S.O.L.I.D. design principles and common OOP patterns. This will help minimize the impact of code changes.
it's days like this I wonder about PHP and what I'm missing
I feel your pain on this one. I haven't used webforms for about 12 months now and haven't looked back. I use Castle Monorail (or MS MVC). Having full control of the html, numerous extension points in the pipeline and removing hacks like postback/events have made web development so much easier.

these exact reasons wouldn't assist you with your current problem of deleting directories, but it does relates the frustrations of webforms.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Thanks for the tips, I'll definitely lookup on that info, I'm all for an easier life, I was just looking at MS MVC actually, considering I use EditPad Pro it seems to be quite a step up :D, I don't have visual studio :(.

When you say name them with a GUID, obviously I could call SQL like.. SELECT GUIDName, USERSETName FROM DB_Files WHERE USERSETName = '1.txt';

and then display "1.txt" but really link it to 6FJR5KRIF7FY4GRMRKF8D6D.txt, but what about if the user wanted to send a direct link to their file, it would have to be and not right ?, sorry if that sounds odd, I'm officially out of my knowledge base.
 
not exactly.

the url might be
*mapping a txt file to be handled by the asp.net pipeline requires some web.config configuration.

using some URL routing you would route the above url to something like

pulling the file from the database is
select * from table where id = @id

the logic would ensure that the user is actually john, or that the file is publicly available for viewing, etc.

you would then set the appropriate headers and write the image byte array to the output stream.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Ahh, I know what you mean, I'm currently doing something to that affect to create thumbnails, thanks for clearing that up and thanks for the help, much appreciated :).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top