Please read the bottom of this post, since the question has been modified.
I have been successful in taking a file off of my computer and sending it to a document library in SharePoint. However, the "Title" column in the document is blank. I would like to set the "Title" column to a certain value, but not sure how to go about it.
Here is the code I use to upload the file
public static async Task PutFileAsync()
{
string genName = App.Generator;
genName = genName.Replace(" ", "-");
StorageLibrary videoLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);
string readFolder = videoLibrary.SaveFolder.Path;
StorageFolder videoFolder = await StorageFolder.GetFolderFromPathAsync(readFolder);
string readFileName = App.Date + "-" + App.StartTime + "-" + App.IBX + "-" + genName + ".xlsx";
StorageFile readFile = await videoFolder.GetFileAsync(readFileName);
byte[] result;
using (Stream stream = await readFile.OpenStreamForReadAsync())
{
using (var memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
result = memoryStream.ToArray();
}
}
var (authResult, message) = await Authentication.AquireTokenAsync();
var httpClient = new HttpClient();
HttpResponseMessage response;
string posturl = MainPage.spfileurl + readFile.Name + ":/content";
var request = new HttpRequestMessage(HttpMethod.Put, posturl);
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
request.Content = new ByteArrayContent(result);
response = await httpClient.SendAsync(request);
var responseString = await response.Content.ReadAsStringAsync();
await Task.Run(() =>
{
File.Delete(readFile.Path);
return TaskStatus.RanToCompletion;
});
}
Any suggestions would be great!
Thanks!
Other information
public static string rooturl = "https://graph.microsoft.com/v1.0/sites/mycompanyinc.sharepoint.com,495435b4-60c3-49b7-8f6e-1d262a120ae5,0fad9f67-35a8-4c0b-892e-113084058c0a/";
string submiturl = rooturl + "lists/18a725ac-83ef-48fb-a5cb-950ca2378fd0/items";
public static string spfileurl = rooturl + "drive/root:/Generator_Runs/";
public static string fileurl = rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/drive/items/01JDP7KXPY64K4C3P4YJC2CJ2IUFG7DAP7/content";
Since it is not possible to add column data while uploading, I need to figure out what the listitem ID is for the file that I just uploaded is.
This is the responseString after the submission
[JSON]
@odata.context: "https://graph.microsoft.com/v1.0/$metadata#sites('mycompanyinc.sharepoint.com%2C495435b4-60c3-49b7-8f6e-1d262a120ae5%2C0fad9f67-35a8-4c0b-892e-113084058c0a')/drive/root/$entity"
@microsoft.graph.downloadUrl: "https://mycompanyinc.sharepoint.com/sites/GeneratorApp/_layouts/15/download.aspx?UniqueId=...&ApiVersion=2.0"
createdDateTime: "12/29/2018 6:43:00 PM"
eTag: ""{BB51689A-9FF5-412C-8B45-D01D2B61A789},2""
id: "01JDP7KXM2NBI3X5M7FRAYWROQDUVWDJ4J"
lastModifiedDateTime: "12/29/2018 6:43:00 PM"
name: "FileNameJ.xlsx"
webUrl: "https://mycompanyinc.sharepoint.com/sites/GeneratorApp/_layouts/15/Doc.aspx?sourcedoc=%7BBB51689A-9FF5-412C-8B45-D01D2B61A789%7D&file=FileName.xlsx&action=default&mobileredirect=true"
cTag: ""c:{BB51689A-9FF5-412C-8B45-D01D2B61A789},4""
size: 47079
createdBy
lastModifiedBy
parentReference
file
fileSystemInfo