PDA

View Full Version : [SLEEPER:] Bad file name or number - Runtime Error 52



Dave_D
11-18-2019, 06:11 AM
I'm using a DIR function to check the existence of asaved file in Sharepoint, but each variation of strFilename used: strFilename = <My URL> & ShrtNamestrFilename = "//teamportalprod1.xxx.org/sites/RCSvcsInfo/RCS_APPS_Productivity/SharedDocuments/Productivity/" & ShrtName strFileExists = Dir(strFilename, vbDirectory) returns a runtime error 52 - "Bad file name ornumber" I am able to save the file using <URL> & ShrtName

snb
11-18-2019, 06:35 AM
Sufficient:


strFileExists = Dir(strFilename)

Dave_D
11-18-2019, 08:02 AM
I just caught an article mentioning that DIR() using the URL will not work, which only leaves me
//teamportalprod1.xxx.org/sites/RCSvcsInfo/RCS_APPS_Productivity/SharedDocuments/Productivity/" & ShrtName as my option. Note taken that vbDirectory is not required, but still receive
runtime error 52 - "Bad file name or number".

snb
11-18-2019, 09:31 AM
vbDirectory is wrong if you are looking for a file.

Paul_Hossler
11-18-2019, 09:41 AM
Don't have SharePoint anymore. but you can try




bFilexists = Dir ("//teamportalprod1.xxx.org/sites/RCSvcsInfo/RCS_APPS_Productivity/SharedDocuments/Productivity/" & ShrtName) <> 0



or



bFilexists = Dir ("\\teamportalprod1.xxx.org\sites\RCSvcsInfo\RCS_APPS_Productivity/SharedDocuments/Productivity/" & ShrtName) <> 0




This post reportedly has a solution, at least for SP2013


https://social.technet.microsoft.com/Forums/ie/en-US/02782b4b-ac0b-4511-b4fa-8796204e0c86/using-excel-vba-how-do-i-test-if-a-file-exists-in-sharepoint-2013?forum=sharepointgeneral

Dave_D
11-18-2019, 12:24 PM
I tried both of your suggestions, each receiving the same "Bad file name or number". I also tried the following code from social.technet.microsoft.com...repointgeneral



Public Function FileExist(SharePointURL As String) As Boolean
' This function check URL exist
' It return true if file exist in sharepoint
' SharePointURL include file extension' IMPORTANT:You need to activate reference "Microsoft WinHTTP Services. version 5.1"!!!!!
Dim RequestSharepoint As New WinHttpRequest
On Error GoTo FileExistError
RequestSharepoint.Open "HEAD", SharePointURL
RequestSharepoint.Send
If RequestSharepoint.Status = 200 Then
FileExist = True
Else
FileExist = False
End If
Exit Function
FileExistError:
FileExist = False
End Function

I passed my URL string and added WinHTTP Services.
This time the RequestSharepoint.Status was a 401; Unauthorized.
I'm starting to believe this issues is more related to administrative rights.
So, I wonder why myself and others are able to straight out able to save the file in SharePoint, but need to be authenticated first, just to verify a file existence.