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

Free Support Forum - aspose.com

Saving copies

Is there a setting to prevent overwriting an existing file when saving a file to a disk location or does this have to be done manually outside of Aspose?

Hi,


This can be done by using standard .NET methods e.g.

string curFile = @“c:\temp\test.txt”;
Console.WriteLine(File.Exists(curFile) ? “File exists.” : “File does not exist.”);

Best regards,

Right, but what I was wondering if Aspose had a setting that would write a copy automatically if the file already exists? Guess not.

Hi,


I think, the following solution will work for you case:

Document doc = new Document(MyDir + @“input.docx”);

string outputFileName = "output.docx";

try

{

// FileFormatUtil.DetectFileFormat throws exception if it could not find file

FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + outputFileName);

// File found with same name. Try saving a copy

doc.Save(MyDir + "copy_" + outputFileName);

}

catch (System.IO.FileNotFoundException ex)

{

// Save with original name

doc.Save(MyDir + outputFileName);

}


Best regards,