Skip to content

Instantly share code, notes, and snippets.

@Mozu-CS
Last active February 15, 2016 17:04
Show Gist options
  • Select an option

  • Save Mozu-CS/96532e4cd7d2bd5f5424 to your computer and use it in GitHub Desktop.

Select an option

Save Mozu-CS/96532e4cd7d2bd5f5424 to your computer and use it in GitHub Desktop.
Upload a file to Mozu File Manager
var filePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\XmlExample\\";
var filename = filePath + "exampleFile.xml";
var documentResource = new Mozu.Api.Resources.Content.Documentlists.DocumentResource(_apiContext);
var documents = documentResource.GetDocumentsAsync("files@mozu", filter: "name eq 'exampleFile.xml'").Result;
var xmlDoc = documents.Items.FirstOrDefault();
var file = System.IO.File.OpenRead(filename);
if(xmlDoc != null && xmlDoc.Name == "exampleFile.xml")
{
xmlDoc.ContentLength = file.Length;
documentResource.DeleteDocumentAsync("files@mozu", xmlDoc.Id).Wait();
xmlDoc.Id = null;
var returnedDoc = documentResource.CreateDocumentAsync(xmlDoc, "files@mozu").Result;
documentResource.UpdateDocumentContentAsync(file, "files@mozu", returnedDoc.Id, contentType: "text/xml").Wait();
}
else
{
var document = new Mozu.Api.Contracts.Content.Document()
{
Name = "exampleFile.xml",
DocumentTypeFQN = "document@mozu",
ContentMimeType = "text/xml",
Extension = "xml",
ContentLength = file.Length
};
var addedDoc = documentResource.CreateDocumentAsync(document, "files@mozu").Result;
documentResource.UpdateDocumentContentAsync(file, "files@mozu", addedDoc.Id, contentType: "text/xml").Wait();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment