We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Load Text file into Document object

Hi,

I am using Aspose.Words dll for .net version 10.5.0.0 to read and load text file contents to document object in a line by line manner. So the process is taking more time to load large size text file. Is there any direct method to load text (.txt) file to document object. Please find the piece of code which i have used to load text file below.

Document _document;

_document = new Document();

DocumentBuilder builder = new DocumentBuilder(_document);

using (StreamReader reader = new StreamReader(filename, encoding))

{

string line = null;

while ((line = reader.ReadLine()) != null)

{

builder.Writeln(line);

}

}

Thanks,

Dhivya

Hi

Thanks for your request. Your code is correct. It is expected that it takes more time to load large files.

Of course you can try reading whole text file into string and then insert this string into document as shown below, but I do not think this way is more efficient:

// Read whole txt file into string.

string txt = File.ReadAllText("in.txt");

// Insert string into document.

DocumentBuilder builder = new DocumentBuilder();

builder.Write(txt);

// Save output.

builder.Document.Save("out.doc");

Best regards,

Hi,

Is there any direct way to convert Text file to tiff format using Aspose SDKs.

Thanks,

Dhivya

Hi

Thanks for your inquiry. No, there is no direct way to achieve this. The only way I can suggest you is inserting text from your txt file into a document and then saving document as tiff.

Best regards,