FP2000: Folders.Add Method Fails on External FilesID: Q219573
|
When you use the Folders.Add method, you receive the following run-time error message:
where MyFolder is the name of the folder you specified to add.Run-time error '-2147467259 (80004005)':
Server Error: 'file:///C:/MyFolder' does not refer to a page or folder in this web. It may be a page or folder in a sub web, or it could be a badly formed URL.
You can not add or import folders to your web that are outside of your web.
The correct way to use Folders.Add method is to create a folder in your web. For example, the following code will create a folder named "MyNewFolder" in your current web:
Sub CreateFolder ()
Dim newfolder as WebFolder
Set newfolder=ActiveWeb.RootFolder.Folders.Add("MyNewFolder")
End Sub
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
To workaround this behavior, use the following sample code. This code creates a new folder called "MyNewFolder" and places all the files from the specified folder into that folder.
Sub importfiles()
Dim mypath, myname, myfile
Dim newfolder As WebFolder
mypath = "c:\My Documents\"
' This is the path location that you wish to get files from.
myname = Dir(mypath, vbDirectory)
Set newfolder = ActiveWeb.RootFolder.Folders.Add("MyNewFolder")
' This creates a new folder in the current web named MyNewFolder
' The following loop goes through each file in each folder in the
' specified file location.
Do While myname <> ""
If myname <> "." And myname <> ".." Then
If (GetAttr(mypath & myname) And vbNormal) = vbNormal Then
ActiveWeb.RootFolder.Folders("MyNewFolder").Files.Add (myname)
' This adds each file name to the folder in the current web
' in the folder named MyNewFolder
End If
End If
myname = Dir
Loop
End Sub
Additional query words: front page
Keywords : kbdta
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 1, 1999