| { | { | ||||
| using (FileStream fs = new FileStream(filename, FileMode.Create)) | using (FileStream fs = new FileStream(filename, FileMode.Create)) | ||||
| { | { | ||||
| CopyStream(memoryStream, fs); | |||||
| } | |||||
| // Original code | |||||
| // fs.Write( memoryStream.ToArray(), 0, (int)memoryStream.Length ); | |||||
| // was replaced by save using small buffer | |||||
| // CopyStream( memoryStream, fs); | |||||
| // Corection is to make position equal to 0 | |||||
| if(memoryStream.CanSeek) | |||||
| { | |||||
| // Write to the beginning of the stream | |||||
| memoryStream.Position = 0; | |||||
| CopyStream(memoryStream, fs); | |||||
| } | |||||
| else | |||||
| fs.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length); | |||||
| } | |||||
| } | } | ||||
| else | else | ||||
| { | { |
| <?xml version="1.0" encoding="utf-8"?> | |||||
| <packages> | |||||
| <package id="NUnit" version="3.6.0" targetFramework="net40" /> | |||||
| <package id="NUnitTestAdapter" version="2.0.0" targetFramework="net40" /> | |||||
| </packages> |
| } | } | ||||
| } | } | ||||
| [Test] | |||||
| [Test] | |||||
| public void Test_DocX_SaveAs() | |||||
| { | |||||
| string temporaryFilePath = Path.Combine( _directoryDocuments, "temp.docx" ); | |||||
| // Load the document 'Paragraphs.docx' | |||||
| using( DocX document = DocX.Load( Path.Combine( _directoryWithFiles, "Paragraphs.docx" ) ) ) | |||||
| { | |||||
| document.InsertParagraph( "text" ); | |||||
| // Test the saving of the document. | |||||
| document.SaveAs( temporaryFilePath ); | |||||
| // Check file size | |||||
| FileInfo f = new FileInfo( temporaryFilePath ); | |||||
| Assert.IsTrue( f.Length == 9659 ); | |||||
| } | |||||
| // Delete the tempory file. | |||||
| File.Delete( temporaryFilePath ); | |||||
| } | |||||
| [Test] | |||||
| public void TableWithSpecifiedWidths() | public void TableWithSpecifiedWidths() | ||||
| { | { | ||||
| using (var output = File.Open(Path.Combine(_directoryWithFiles, "TableSpecifiedWidths.docx"), FileMode.Create)) | using (var output = File.Open(Path.Combine(_directoryWithFiles, "TableSpecifiedWidths.docx"), FileMode.Create)) |
| </AssemblyOriginatorKeyFile> | </AssemblyOriginatorKeyFile> | ||||
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> | |||||
| <HintPath>..\packages\nunit.framework.2.63.0\lib\nunit.framework.dll</HintPath> | |||||
| <Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> | |||||
| <HintPath>..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll</HintPath> | |||||
| <Private>True</Private> | <Private>True</Private> | ||||
| </Reference> | </Reference> | ||||
| <Reference Include="System" /> | <Reference Include="System" /> |
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||
| <packages> | <packages> | ||||
| <package id="NUnit" version="3.4.1" targetFramework="net40" /> | |||||
| <package id="NUnit" version="3.6.0" targetFramework="net40" /> | |||||
| <package id="NUnit.Console" version="3.4.1" targetFramework="net40" /> | <package id="NUnit.Console" version="3.4.1" targetFramework="net40" /> | ||||
| <package id="NUnit.ConsoleRunner" version="3.4.1" targetFramework="net40" /> | <package id="NUnit.ConsoleRunner" version="3.4.1" targetFramework="net40" /> | ||||
| <package id="NUnit.Extension.NUnitProjectLoader" version="3.4.1" targetFramework="net40" /> | <package id="NUnit.Extension.NUnitProjectLoader" version="3.4.1" targetFramework="net40" /> |