Hello all, i use this piece of code to copy a MSWord document.
Dim ThisMoment As Date
Dim myFileName, f As String
ThisMoment = Now
f = ThisMoment.ToString("ddmmyyhhmmss") & ".doc"
myFileName = "F:\Projects\" & f
Dim fso As New Scripting.FileSystemObject()
fso.CopyFile("F:\Projects\Original.doc", myFileName, False)
fso = Nothing
All works fine but when i double click on the copy then MSWord opens it and then asks me if i want to make a copy because another user has this file in use. I am sure i am the only one. Have
i forgot to close anything or breakup a connection? As always thanks, Dennis
First I need to ask, is this a .Net application you're working with? And if so, why are you working with the FileSystemObject, which is not part of the .Net framework, and not with the Classes found within the System.IO Namespace?
Yes absolutely but i see that i have a lot to learn. I use old stuff. Thats why i had to import some scripting dll. You know Project -> Reference -> Com tab etc... Without it i couldn't compile my code. At the top of my code(behind) i use Imports System.IO
but i don't use it. Look i am kinda new with asp.net but i quess i should use the FILE object don't i. A little help (code snippet) to get started would be very much appreaciated. Thanks, Dennis
It's quite simple really. Start by importing the System.IO Namespace:
Imports System.IO
Then use this code in e.g. a Button_Click eventhandler:
Dim myNewFile As String = Server.MapPath("") & "/" & DateTime.Now().ToString("d") & ".doc"
Dim myOrgFile As String = Server.MapPath("") & "/" & "Original.doc"
'Use Move to overwrite the Old file with a new file
'Use Copy with True as a 3rd argument to Copy the original to the new file
File.Move/Copy(myOrgFile, myNewFile[, True])
Label1.Text = "File overwritten"
It takes a little getting used to that one can use the whole .NET code library from in my case VB.NET. I am a bit of an old school programmer so it takes a little time getting to grips with this idea. Everything one normaly needs is in there isn't it? (.NET
code library) Thanks Andre, ( and for the code ) Dennis
DennisTheMan...
Member
275 Points
55 Posts
Copied file used by another user??
Aug 01, 2003 05:41 AM|LINK
Dim ThisMoment As Date Dim myFileName, f As String ThisMoment = Now f = ThisMoment.ToString("ddmmyyhhmmss") & ".doc" myFileName = "F:\Projects\" & f Dim fso As New Scripting.FileSystemObject() fso.CopyFile("F:\Projects\Original.doc", myFileName, False) fso = NothingAll works fine but when i double click on the copy then MSWord opens it and then asks me if i want to make a copy because another user has this file in use. I am sure i am the only one. Have i forgot to close anything or breakup a connection? As always thanks, Dennisadec
Star
12495 Points
2491 Posts
Re: Copied file used by another user??
Aug 01, 2003 06:07 AM|LINK
Andre Colbiornsen
DennisTheMan...
Member
275 Points
55 Posts
Re: Copied file used by another user??
Aug 01, 2003 06:39 AM|LINK
adec
Star
12495 Points
2491 Posts
Re: Copied file used by another user??
Aug 01, 2003 07:02 AM|LINK
Dim myNewFile As String = Server.MapPath("") & "/" & DateTime.Now().ToString("d") & ".doc" Dim myOrgFile As String = Server.MapPath("") & "/" & "Original.doc" 'Use Move to overwrite the Old file with a new file 'Use Copy with True as a 3rd argument to Copy the original to the new file File.Move/Copy(myOrgFile, myNewFile[, True]) Label1.Text = "File overwritten"Andre Colbiornsen
DennisTheMan...
Member
275 Points
55 Posts
Re: Copied file used by another user??
Aug 01, 2003 07:18 AM|LINK
adec
Star
12495 Points
2491 Posts
Re: Copied file used by another user??
Aug 01, 2003 09:18 AM|LINK
Andre Colbiornsen