[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Upload picture to a SharePoint Picture Library from URL

Posted on 2011-11-01
2
Medium Priority
?
639 Views
Last Modified: 2012-08-14
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

0
Comment
Question by:hqdev
  • 2
2 Comments
 

Author Comment

by:hqdev
ID: 37063355
Found the solution myself
0
 

Accepted Solution

by:
hqdev earned 0 total points
ID: 37063360
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

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question