using file.move - how to close all connections on file before attempt?

hey guys,

i'm using file.move quite a bit in this project because it's an image gallery and i want users to be able to delete their files. however instead of actually deleting them, i'm using file.move to put them in a locked directory, just incase some sort of authority came asking about a file that someone tried to delete awhile ago. anyway i'm getting errors when trying SOMETIMES, because of your standard windows 'file is in use' error when trying to delete or move something.

File.Move("C:\\files\\" + ((Label)gvr.FindControl("Label3")).Text, "C:\\deleted\\" + ((Label)gvr.FindControl("Label3")).Text);


 the above is essentially my code for the linkbutton DELETE in a column for a gridview. it works fine assuming the image isn't or wasn't in use recently, but if it was, the user gets a windows error message in their browser and the file doesn't move. is there a way to force a kill of all possible connections to a file before attempting the file.move?

0
orion846
8/14/2008 5:50:27 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
593 Views

Similar Articles

[PageSpeed] 49

 put the whole thing in a try catch block
try
{
  // delete
}
catch
{
  // catch exception
}

 


ROAMER!

if (myReply.Equals(YourAnswer))
{
MarkThisThread = "Answerd";
}
0
ROAMER
8/14/2008 6:57:25 AM

nice idea, but won't that just keep failing if an open connection is on the file? that's preferable to the error message they're receiving obviously, but it doesn't totally solve the problem. i'm sort of leaving people to the whims of random 'file in use' messages that they won't be able to get around. 

0
orion846
8/14/2008 12:27:11 PM

Hi,

If the file resource is not released by another process, it will throw the exception. How did you use this file before deleting it? If we want to open it, we can use FileShare Enumeration (http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx ) to open this file.

I suggest you release the file resource with Using statement or call Dispose method, if it can be disposabled. For instance, we need to call FileStream's Dispose method.

To detect if the file has been opened, you also can open the file with FileShare.None, and then if you want to open it again, the operation is failed. So you can use Try/Catch block to catch this System.IO.IOException, and then display the warning message.

Sometimes, we need to wait in a loop to delete this file until this file is released by another user. We can do this in background thread.


I look forward to hearing from you.


Thomas Sun
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Thomas
8/19/2008 5:39:23 AM

that all sounded very logical and like it's what i'm looking for (particularly the wait loop until file released) but i'm a novice and could use some help with the code. code to check if a file is in use and repeatedly check until it's not, than do something.

PS: you asked why a file might be in use and not moveable, i don't know exactly, seems like if a file has been recently (last 10 minutes) uploaded, then it cannot be moved.

i'll check out this link you've shared as well, thank you.
 

0
orion846
8/19/2008 12:02:37 PM
Reply:

Similar Artilces:

FTP: Delete File, Move File, Get File Properties (?)
Hi! Using the inet object, how can I (a) Delete an object from the FTP server (b) Move a file from one folder to another on the FTP server (c) Get file properties on a given file (e.g. datetime and size) Thanks! D I think I figured it out..... "Daniel Coppersmith" <daniel@N.0.S.P.A.M_infrontsoftware.com> wrote in message news:#qfwscFpCHA.199@forums.sybase.com... > Hi! > > Using the inet object, how can I > (a) Delete an object from the FTP server > (b) Move a file from one folder to another on the FTP server > ...

Why we use Web.Config File for connection string wether we can use class Library for get connection for whole web Application
 Why we use Web.Config File for connection string wether we can use class Library for get connection for whole web Application  please help me? Friend, Web.config has its own advantages. 1) Web.Config is used to store the important information like connections strings etc...so that it can be modified even after the code has been    deployed to the server without compiling the entire application again. 2) Since it is a XML file, there is no need of building the project of you are going to change the connection strings.   If you go for the class files,...

superreview requested: [Bug 298460] Use xhtml files in content instead of html files in locale : [Attachment 187065] Move both html files
Pavel Franc - Pawell (Czilla.cz) <p.franc@gmail.com> has asked Scott MacGregor <mscott@mozilla.org> for superreview: Bug 298460: Use xhtml files in content instead of html files in locale https://bugzilla.mozilla.org/show_bug.cgi?id=298460 Attachment 187065: Move both html files https://bugzilla.mozilla.org/attachment.cgi?id=187065&action=edit ------- Additional Comments from Pavel Franc - Pawell (Czilla.cz) <p.franc@gmail.com> This is a patch for both credits.html and start.html. After aplaying the patch you need to move mail/locales/en-US/chrome/messenger/s...

superreview granted: [Bug 298460] Use xhtml files in content instead of html files in locale : [Attachment 187065] Move both html files
Scott MacGregor <mscott@mozilla.org> has granted Pavel Franc - Pawell (Czilla.cz) <p.franc@gmail.com>'s request for superreview: Bug 298460: Use xhtml files in content instead of html files in locale https://bugzilla.mozilla.org/show_bug.cgi?id=298460 Attachment 187065: Move both html files https://bugzilla.mozilla.org/attachment.cgi?id=187065&action=edit ------- Additional Comments from Scott MacGregor <mscott@mozilla.org> thanks for the patch. This one works much better ...

How to convert .tiff image file to .pdf file without using any 3rd party tool using C#.net
HI allI have a urgent requirement i want to convert .tiff image to .pdf file Thanks in advance Regards RaviPlease click "mark as answer" if this post helped you. I dont think its possible without doing a lot of code or using third party tools, but if you  are looking for a free tool you can try a combination of http://blog.codebeach.com/2008/02/convert-multipage-tiff-to-pdf-in-net.htmland  http://www.codeproject.com/KB/aspnet/Creating_PDF_documents_in.aspx Thanks and RegardsS.K.Vignesh----------------------Do remember to "Mark as answer" for this pos...

Add water mark using PJL and Get the file path for print jobs or Get copy of the print jobs file.
Hi,  I want to know how to set water mark to Hp printer using PJL and I want to know how to get the file path for print jobs. I got print job document names. But i want to get copy of the print jobs file. ...

Keep getting..."Unable to get project file from server",when using vs.net
When trying to open any existing asp.net project in Visual Studio it keeps giving me the message above. It is also throwing an error when I create the project in the first place, it happens when a dos window is opened, the text in the dos window is running "Common Language Runtime Minidump Utility version 1.0.3705.0" and then VS craps out says there was an error and shuts down. I've re-installed the .net components and framework with no avail, and FrontPage extensions etc.. are all installed. I'm running XP professional and have installed IIS 5.1. This is driving me fec...

File.move in vb.net (using *.*)
Hi, Is there of way of moving all file in a directory evan if you dont know the dile names say with *.* I have tried using "file.move" but it does not seam to support multiple files. Thanls Joolz you'd have to loop through the directory moving each file individually, I reckon. or maybe you can move the entire folder in one operation, rather than all files in one operation.RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unreadableJason Brown - MVP, IIS...

to file:// or not to file://
(Firefox 1.5.0.6) I'm having trouble with HTML Anchors (links) using the file: protocol. The URL I'm trying to get at looks something like this file://///Host.Domain/Share/Dir1/Dir2/File.Ext If I click on the link, /nothing/ happens but, if I "Copy Link Location" and paste exactly the same thing into the "address bar" in FireFox, FireFox is perfectly happy to show me the file. Why the difference? Am I tripping over some security restriction here? Any suggestions? TIA, Phill W. Phill W. wrote: > (Firefox 1.5.0.6) > I'm ...

outlook file DBX file extract using vb.net
hi i want to read email in dbx file using vb.net plase help me .... Dear, U can see the below link: http://groups.google.de/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/1d037d2c7bc46a98/Kind Regards,Saurabh Sharmaonly dead fish swim along the flow of river, learn to make your own way.Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread...

How to get the load address of the .net executable file(exe file) ?
hello: I am reading an article about .net(Rewrite MSIL Code on the Fly with the .NET Framework Profiling API)from msdn, http://msdn.microsoft.com/msdnmag/issues/03/09/NETProfilingAPI/ ,but i have some trouble about it . it said : If you added the method's RVA to the load address (the address where the executable file for the "Hello World!" assembly was loaded), you would see a memory dump layout similar to the one shown in Figure 3. On my machine, the load address was 0x06EA1000, I want to know : how can i get the load address of the exe file on my machine?is there s...

How to Create .mdb file from Excel file using C#.net
Hi all I want to create .mdb file that i have created excel feel from MS jet Database... through code behind Help me in this..  Regards RaviPlease click "mark as answer" if this post helped you. How to create an mdb file programmtically:http://support.microsoft.com/kb/317881How to import Excel data into it: http://www.mikesdotnetting.com/Article.aspx?ArticleID=79 Regards Mike [MVP - ASP/ASP.NET]My site...

Pls post code to start/open an Excel file and then close the file
Pls post :- (1) Codes to start/open a particular Excel file (eg xyz.XLS in path c:\abc) and(2) Codes to save this XLS and(3) codes to close this XLS file preferably in VB. I want to just keep the Excel file opened and saved at the background (ie without notice to users. Thanks a lot.Thanks in advance for the help. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped. Please help !!!Thanks in advance for the help. I will try to credit the ones who helped but most important is we really do sincerely thanks ...

unintelligible file name when using Response to download a file. VB.net
I have a website that shows a list of files stored in the server. Here is the code:Dim ObjFileinfo As New FileInfo(strRootPath) Response.Clear() Response.AddHeader("Content-Disposition", "attachement;filename=" & strFileName) 'NOTE: strFile Name contains the name in Russian, if I Response.Write(strFileName)'I get the proper Russian name displayed on the page so I am sure that I am passing the right oneResponse.AddHeader("Content_Length", ObjFileinfo.Length.ToString()) Response.ContentType = "application/octet-stream" Response.Transm...

Web resources about - using file.move - how to close all connections on file before attempt? - asp.net.getting-started

Connection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

iMedia Connection: Interactive Marketing News, Features, Podcasts and Video - iMediaConnection.com
High-quality data, if not used properly, can still lead marketers to make bad decisions. Consider these common ways that numbers are used to ...

HTTP persistent connection - Wikipedia, the free encyclopedia
... tacked on to an existing protocol. If the browser supports keep-alive, it adds an additional header to the request: Following this, the connection ...

CareerSonar Turns Facebook Friends Into Job Connections
Looking for a job ? Among your Facebook friends lies the potential for employment. CareerSonar , a new service, brings together a person’s connections ...

Ben Garcia gives Penrith Panthers a new French connection
Should he jag a game in the NRL, Ben Garcia will become just the third genuine French import to do so.

Man Charged With Aggravated Arson In Connection To Columbus Warehouse Fire
Police have charged 30-year-old Robin Toms with aggravated arson.

Facebook becomes more adept at dealing with crappy connections
... to get a decent phone signal to allow you to post a photo of your meal. Joking aside, in countries where people are struggling with 2G connections ...

Adam Savage from 'MythBusters' has an incredible connection to the 'Star Wars' franchise
Adam Savage, co-host of the popular " MythBusters " television show, soured on the plot of "Interstellar." But when it comes to the newest films ...

French authorities detain suspects in connection to attacks 10 months apart
CNN French authorities detain suspects in connection to attacks 10 months apart CNN A forensic scientist works near a Paris cafe on Saturday, ...

UK Police Make Arrest in Connection With VTech Hacking
British law enforcement officials arrest a 21-year-old man in connection with attack on toy maker VTech that exposed 6 million parents and children ...

Resources last updated: 12/24/2015 7:35:40 PM