|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File lockAt some point in my application I load an image into a picturebox with the
code: pbGraphic.Image = Image.FromFile("picture.jpg") Later on in the program I want to rename the file using the code: pbGraphic.Image = Nothing My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") but I get an IOException: "The process cannot access the file because it is being used by another process." Why is the original file still locked and what can I do to unlock it? Any help is welcome. Tnxs Jos Roijakkers wrote:
> At some point in my application I load an image into a picturebox You have to tell it you've really, really finished with it using > with the code: > > pbGraphic.Image = Image.FromFile("picture.jpg") > > Later on in the program I want to rename the file using the code: > > pbGraphic.Image = Nothing > My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") > > but I get an IOException: "The process cannot access the file because > it is being used by another process." > Why is the original file still locked and what can I do to unlock it? ..Dispose():- pbGraphic.Image = Nothing pbGraphic.Dispose() My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") And I'm fairly sure you should be giving the full path for the original and new names in the RenameFile(). Andrew Unfortunately, adding Dispose() makes no difference.
Re the filenames: the original name should be given with a full path, the new name should not have the full path. Show quoteHide quote > Jos Roijakkers wrote: > >> At some point in my application I load an image into a picturebox >> with the code: >> >> pbGraphic.Image = Image.FromFile("picture.jpg") >> >> Later on in the program I want to rename the file using the code: >> >> pbGraphic.Image = Nothing >> My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") >> but I get an IOException: "The process cannot access the file because >> it is being used by another process." >> Why is the original file still locked and what can I do to unlock it? > You have to tell it you've really, really finished with it using > .Dispose():- > > pbGraphic.Image = Nothing > pbGraphic.Dispose() > My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") > And I'm fairly sure you should be giving the full path for the > original and new names in the RenameFile(). > > Andrew >
Show quote
Hide quote
>> Jos Roijakkers wrote: Jos Roijakkers wrote:>> >>> At some point in my application I load an image into a picturebox >>> with the code: >>> >>> pbGraphic.Image = Image.FromFile("picture.jpg") >>> >>> Later on in the program I want to rename the file using the code: >>> >>> pbGraphic.Image = Nothing >>> My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") >>> but I get an IOException: "The process cannot access the file >>> because it is being used by another process." >>> Why is the original file still locked and what can I do to unlock >>> it? >> You have to tell it you've really, really finished with it using >> .Dispose():- >> >> pbGraphic.Image = Nothing >> pbGraphic.Dispose() >> My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") >> And I'm fairly sure you should be giving the full path for the >> original and new names in the RenameFile(). > Unfortunately, adding Dispose() makes no difference. If you use a program like Unlocker (http://ccollomb.free.fr/unlocker/) you > can see which other process has the file open. I had a problem once with a source control program obtaining a handle to text files in the same directory as the app. > Re the filenames: the original name should be given with a full path, I only have .NET 1.1 here, so I don't have the 2.0 docs to hand.> the new name should not have the full path. What happens if you use the VB Rename function? Or System.IO.File.Move? (nothing different, at a guess). Andrew Thanks Andrew for your help.
The VB Rename function gives an error: "ArgumentException was not handled; Procedure call or argument is not valid" System.IO.File.Move gives the same IOException as the RenameFile function. The Unlocker program shows no other locks on the file than the application itself. So I guess I have to unlock the file right after loading it into the picturebox. But I don't have any clue on how to do that. Jos Show quoteHide quote >>> Jos Roijakkers wrote: >>> >>>> At some point in my application I load an image into a picturebox >>>> with the code: >>>> >>>> pbGraphic.Image = Image.FromFile("picture.jpg") >>>> >>>> Later on in the program I want to rename the file using the code: >>>> >>>> pbGraphic.Image = Nothing >>>> My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") >>>> but I get an IOException: "The process cannot access the file >>>> because it is being used by another process." >>>> Why is the original file still locked and what can I do to unlock >>>> it? >>> You have to tell it you've really, really finished with it using >>> .Dispose():- >>> >>> pbGraphic.Image = Nothing >>> pbGraphic.Dispose() >>> My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") >>> And I'm fairly sure you should be giving the full path for the >>> original and new names in the RenameFile(). > Jos Roijakkers wrote: > >> Unfortunately, adding Dispose() makes no difference. >> > If you use a program like Unlocker (http://ccollomb.free.fr/unlocker/) > you can see which other process has the file open. I had a problem > once with a source control program obtaining a handle to text files in > the same directory as the app. > >> Re the filenames: the original name should be given with a full path, >> the new name should not have the full path. >> > I only have .NET 1.1 here, so I don't have the 2.0 docs to hand. > What happens if you use the VB Rename function? Or > System.IO.File.Move? > (nothing different, at a guess). > Andrew > "Jos Roijakkers" <j.roijakk***@qred-it.nl> schrieb: <URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>> pbGraphic.Image = Image.FromFile("picture.jpg") > > Later on in the program I want to rename the file using the code: > > pbGraphic.Image = Nothing > My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") > > but I get an IOException: "The process cannot access the file because it > is being used by another process." -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Thanks a lot. I've got it working now.
Vielen Dank! Jos Show quoteHide quote > "Jos Roijakkers" <j.roijakk***@qred-it.nl> schrieb: > >> pbGraphic.Image = Image.FromFile("picture.jpg") >> >> Later on in the program I want to rename the file using the code: >> >> pbGraphic.Image = Nothing >> My.Computer.FileSystem.RenameFile("picture.jpg","newname.jpg") >> but I get an IOException: "The process cannot access the file because >> it is being used by another process." >> > <URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock> >
AccessDB on a WebServer
Server calls client behind firewall/NAT convert byte() in ASCII code to letters? Need one Regular Expression word automation bookmarks Setting Limitation to number of Rows in DataGrid? DataGrid / Dataset / DataAdaptor / DataBase updat problem - please Access mdb file on server Raise Maximum Compiler Error Limit? desktop color picker |
|||||||||||||||||||||||