SP2016 On Prem:
Utltimate Goal: Pull files from Sharepoint Document libraries and place onto file server.
I'm using this Sharepoint api to read the data from the file:
I can download the file data from the api, then manually launch Word and open that file. It looks perfect.
But now I need to create those files programatically on a file server using visual basic.
It works great when it's a simple text file, but with Word docs I get the error:
We're sorry. We can't open myWordDoc.docx because we found a problem with its contents.
I've tried 2 methods to create and populate the file:
Sub CreateFile(filename As String, newText As String) Dim path As String = "c:\temp\" + filename Dim sw As StreamWriter ' Create or overwrite the file. sw = File.AppendText(path) sw.WriteLine(newText) sw.Dispose() End Sub
Sub CreateFile(filename As String, newText As String) Dim path As String = "c:\temp\" + filename Dim fs As FileStream = File.Create(path) Dim info As Byte() = New System.Text.UTF8Encoding(True).GetBytes(newText) fs.Write(info, 0, info.Length) fs.Close() End Sub
I assume I need to encode the text somehow but I don't know what else to try.
Eventually I need to do this with Excel, ppt and pdf files too so I need something generic.
If you know of a way to simply grab the files and move them that would be better, but I don't know how I can do that using the sharepoint api.
copyto api can only copy files between sharepoint sites, it can't access the file system.