Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active September 27, 2021 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-cloud/6b5d0495c3ac32814640177c9bec736c to your computer and use it in GitHub Desktop.
Save aspose-cloud/6b5d0495c3ac32814640177c9bec736c to your computer and use it in GitHub Desktop.
This Gist contains code snippets related to the conversion of MPP files to XML format using Aspose.Tasks Cloud SDK for .NET
This Gist contains code snippets related to the conversion of MPP files to XML format using Aspose.Tasks Cloud SDK for .NET
// Get ClientID from https://dashboard.aspose.cloud/
string clientSecret = "d757548a9f2558c39c2feebdf85b4c44";
string clientID = "4db2f826-bf9c-42e7-8b2a-8cbca2d15553";
// create TasksApi instance
TasksApi tasksApi = new TasksApi(clientSecret, clientID);
// input MPP file name
String inputFile = "Home move plan.mpp";
// resultant XML file name
String resultant = "Converted.xml";
try
{
// read the project document from local system into stream instance
using (var inputStream = new FileStream("C:\\Users\\shahbnay\\Downloads\\"+inputFile, FileMode.Open))
{
var uploadFileRequest = new PostCreateRequest("Home move plan.mpp", inputStream);
// upload file to cloud storage
tasksApi.UploadFile(uploadFileRequest);
}
// create MPP file conversion request
var request = new GetTaskDocumentWithFormatRequest();
// specify the input MPP name from cloud storage
request.Name = inputFile;
// set XML as resultant format
request.Format = Aspose.Tasks.Cloud.Sdk.Model.ProjectFileFormat.Xml;
// If parameter is true, HTML resources are included as separate files and
// returned along with the resulting html file as a zip package.
request.ReturnAsZipArchive = false;
// perform document conversion operation
Stream response = tasksApi.GetTaskDocumentWithFormat(request);
if (response != null)
{
Console.WriteLine("Successfully converted MPP to XML !");
}
// custom method to save resultant file on local system drive
saveToDisk(response, "C:\\Users\\shahbnay\\Downloads\\" + resultant);
}catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
// method to save stream content as file object
static void saveToDisk(Stream responseStream, String resultantFile)
{
var fileStream = File.Create(resultantFile);
responseStream.Seek(0, SeekOrigin.Begin);
responseStream.CopyTo(fileStream);
fileStream.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment