Last active
February 15, 2016 17:04
-
-
Save Mozu-CS/96532e4cd7d2bd5f5424 to your computer and use it in GitHub Desktop.
Upload a file to Mozu File Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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