Skip to content

Commit 9499373

Browse files
Added using
1 parent a911f21 commit 9499373

File tree

1 file changed

+17
-10
lines changed
  • Paragraphs/Resize_Images_to_fit_Owner_Element/.NET/Resize_Images_to_fit_Owner_Element

1 file changed

+17
-10
lines changed

Paragraphs/Resize_Images_to_fit_Owner_Element/.NET/Resize_Images_to_fit_Owner_Element/Program.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@ internal class Program
77
{
88
static void Main(string[] args)
99
{
10-
// Create a new Word document instance
11-
WordDocument document = new WordDocument();
12-
// Enable automatic image resizing
13-
document.Settings.ResizeImageToFitInContainer = true;
14-
// Open the template document
15-
document.Open(Path.GetFullPath(@"Data/InputDocument.docx"), FormatType.Docx);
16-
// Save the modified document
17-
document.Save(Path.GetFullPath(@"Output/Result.docx"), FormatType.Docx);
18-
// Release resources
19-
document.Dispose();
10+
// Create a new Word document
11+
using (WordDocument document = new WordDocument())
12+
{
13+
// Enable automatic image resizing
14+
document.Settings.ResizeImageToFitInContainer = true;
15+
// Open the template document
16+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/InputDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
17+
{
18+
document.Open(fileStreamPath, FormatType.Automatic);
19+
}
20+
//Creates file stream.
21+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
22+
{
23+
//Saves the Word document to file stream.
24+
document.Save(outputFileStream, FormatType.Docx);
25+
}
26+
}
2027
}
2128
}
2229
}

0 commit comments

Comments
 (0)