Programmatically Download File From Sharepoint Site

ArmDezii 41 Reputation points
2022-05-17T16:08:41.027+00:00

I have tried every conceivable way to Programmatically Download a File (*.jpg) from a Sharepoint Site. Initially, I was successful, but then it simply stopped working. Can anyone give me some insight into this? The Code is posted below, minus the API Declarations which I know are correct. The proper File is generated and the URL is correct, but it simply will not Open (improper format). Thanks in advance.
'*********************************************** TEST PARAMETERS ***********************************************
Const conFILE_NAME = "Gates, Bill.jpg"
Const conPHOTO_PATH = "C:\Usher_Photos"
Const conURL_PATH_TO_PHOTO = "https://organization.sharepoint.com/sites/MySite/Shared%20Documents/FOHdata/" & _
"Usher%20Photos/Active/"
'***************************************************************************************************************

lngCache = DeleteUrlCacheEntry(conURL_PATH_TO_PHOTO & Replace(conFILE_NAME, " ", "%20"))    'Encode the Space?

If Dir(conPHOTO_PATH, vbDirectory) = "" Then
  MkDir conPHOTO_PATH
Else
  If Dir(conPHOTO_PATH & "\*.jpg") <> "" Then Kill conPHOTO_PATH & "\*.jpg"
    lngRetVal = URLDownloadToFile(0, conURL_PATH_TO_PHOTO & conFILE_NAME, conPHOTO_PATH & "\" & conFILE_NAME, 0, 0)
End If
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,402 questions
{count} votes

Accepted answer
  1. Tong Zhang_MSFT 9,116 Reputation points
    2022-05-18T08:27:17.013+00:00

    Hi @ArmDezii ,

    Our forum mainly discuss about SharePoint development using C#, Since your question is about VBA , we suggest you create a new thread on techcommunity for help, more professional will assist you.

    techcommunity :

    https://techcommunity.microsoft.com/t5/sharepoint-developer/bd-p/SharePointDev


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



0 additional answers

Sort by: Most helpful