Upload picture to a SharePoint Picture Library from URL

Hi Experts,
I'm trying to upload a picture to a SharePoint picture library from my ASP.NET application.
I can do it from a local file, but I want to take a default picture from the picture library itself and upload a copy of that with a different name.
I've included the code which work for a local file but not from a URL.

Thanks
Dim docSetFolder As Folder = oWebsite.GetFolderByServerRelativeUrl("http://p605912/FichesContacts")
Dim fci As New FileCreationInformation()
fci.Url = "http://p605912/FichesContacts/" & strMat & ".png"
fci.Content = System.IO.File.ReadAllBytes("http://p605912/FichesContacts/$90000000.png") <=== DOESNT WORK FOR URL ONLY FOR LOCAL
Dim documentFiles As FileCollection = docSetFolder.Files
clientContext.Load(documentFiles)
Dim newFile As File = documentFiles.Add(fci)

clientContext.Load(newFile)
oListItem = newFile.ListItemAllFields
oListItem("TypeNo") = "Individu"
oListItem("NomFamille") = Trim(IIf(IsDBNull(r.Item("indv_nom")), "", r.Item("indv_nom")))
oListItem("Prenom") = Trim(IIf(IsDBNull(r.Item("indv_prenom")), "", r.Item("indv_prenom")))
oListItem("Telephone") = Trim(IIf(IsDBNull(r.Item("indv_tel")), "", r.Item("indv_tel")))
oListItem("courriel") = Trim(IIf(IsDBNull(r.Item("indv_email")), "", r.Item("indv_email")))
oListItem("cellulaire") = Trim(IIf(IsDBNull(r.Item("indv_cel")), "", r.Item("indv_cel")))
oListItem("Emplacement") = Trim(IIf(IsDBNull(r.Item("indv_emp")), "", r.Item("indv_emp")))
oListItem("Direction") = Trim(IIf(IsDBNull(r.Item("indv_dir")), "", r.Item("indv_dir")))
oListItem("vp") = Trim(IIf(IsDBNull(r.Item("indv_vp")), "", r.Item("indv_vp")))
oListItem("Superieur") = Trim(IIf(IsDBNull(r.Item("indv_supname")), "", r.Item("indv_supname")))
oListItem("Site") = Trim(IIf(IsDBNull(r.Item("indv_site")), "", r.Item("indv_site")))
oListItem("Edifice") = Trim(IIf(IsDBNull(r.Item("indv_edifice")), "", r.Item("indv_edifice")))
oListItem("matsup") = Trim(IIf(IsDBNull(r.Item("indv_supmat")), "", r.Item("indv_supmat")))
oListItem("Fonction") = Trim(IIf(IsDBNull(r.Item("indv_fonction")), "", r.Item("indv_fonction")))
oListItem.Update()

clientContext.Load(oListItem)

Open in new window

hqdevAsked:
Who is Participating?
 
hqdevConnect With a Mentor Author Commented:
Here's the correct way to do it.
Dim fInfo As FileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, "/FichesContacts/$90000000.png")
                Dim memStream As New System.IO.MemoryStream()
                Dim buffer(2047) As Byte

                Dim bytesRead As Integer = 0
                Do
                    bytesRead = fInfo.Stream.Read(buffer, 0, buffer.Length)
                    memStream.Write(buffer, 0, bytesRead)
                Loop While bytesRead <> 0
                fInfo.Stream.Close()
                buffer = memStream.ToArray()


                Dim docSetFolder As Folder = oWebsite.GetFolderByServerRelativeUrl("http://p605912/FichesContacts")
           
                Dim fci As New FileCreationInformation()
                fci.Url = "http://p605912/FichesContacts/" & strMat & ".png"
                fci.Content = buffer
                Dim documentFiles As FileCollection = docSetFolder.Files
                clientContext.Load(documentFiles)
                Dim newFile As File = documentFiles.Add(fci)

                clientContext.Load(newFile)
                oListItem = newFile.ListItemAllFields
                oListItem("TypeNo") = "Individu"
                oListItem("NomFamille") = Trim(IIf(IsDBNull(r.Item("indv_nom")), "", r.Item("indv_nom")))
                oListItem("Prenom") = Trim(IIf(IsDBNull(r.Item("indv_prenom")), "", r.Item("indv_prenom")))
                oListItem("Telephone") = Trim(IIf(IsDBNull(r.Item("indv_tel")), "", r.Item("indv_tel")))
                oListItem("courriel") = Trim(IIf(IsDBNull(r.Item("indv_email")), "", r.Item("indv_email")))
                oListItem("cellulaire") = Trim(IIf(IsDBNull(r.Item("indv_cel")), "", r.Item("indv_cel")))
                oListItem("Emplacement") = Trim(IIf(IsDBNull(r.Item("indv_emp")), "", r.Item("indv_emp")))
                oListItem("Direction") = Trim(IIf(IsDBNull(r.Item("indv_dir")), "", r.Item("indv_dir")))
                oListItem("vp") = Trim(IIf(IsDBNull(r.Item("indv_vp")), "", r.Item("indv_vp")))
                oListItem("Superieur") = Trim(IIf(IsDBNull(r.Item("indv_supname")), "", r.Item("indv_supname")))
                oListItem("Site") = Trim(IIf(IsDBNull(r.Item("indv_site")), "", r.Item("indv_site")))
                oListItem("Edifice") = Trim(IIf(IsDBNull(r.Item("indv_edifice")), "", r.Item("indv_edifice")))
                oListItem("matsup") = Trim(IIf(IsDBNull(r.Item("indv_supmat")), "", r.Item("indv_supmat")))
                oListItem("Fonction") = Trim(IIf(IsDBNull(r.Item("indv_fonction")), "", r.Item("indv_fonction")))
                oListItem.Update()

                clientContext.Load(oListItem)

Open in new window

0
 
hqdevAuthor Commented:
Found the solution myself
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.