Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This Gist contains code snippets related to the conversion of Microsoft DOC file to ODT format using C# .NET
This Gist contains code snippets related to the conversion of Microsoft DOC file to ODT format using C# .NET
// Get ClientID from https://dashboard.aspose.cloud/
string clientSecret = "caac6e3d4a4724b2feb53f4e460eade3";
string clientID = "4ccf1790-accc-41e9-8d18-a78dbb2ed1aa";
// create configuration object using ClinetID and Client Secret details
var config = new Configuration { ClientId = clientID, ClientSecret = clientSecret };
// initialize WordsApi instance
var wordsApi = new WordsApi(config);
// input file name
String inputFile = "sample.doc";
// name of resultant file
String resultant = "conveted.odt";
// resultant file format
String format = "ODT";
try
{
// load input DOC file in Stream instance
using (var inputStream = new FileStream("/Users/nshahbaz/Downloads/" + inputFile, FileMode.Open))
{
// load input file stream and create ConvertDocument request instance
var convertRequest = new ConvertDocumentRequest(inputStream, format);
// perform the document conversion and save output in response object
var response = wordsApi.ConvertDocument(convertRequest);
if (response != null )
{
Console.WriteLine("Successfully converted DOC to ODT !");
}
// save the output on local system drive
saveToDisk(response, "/Users/nshahbaz/Downloads/" + resultant);
}
}catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
// save the file on system drive
public 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