Working With Document File Stream PDF
Working With Document File Stream PDF
Portal > Knowledgebase > GemBox.Document > Working with document file stream
GemBox.Document provides few overload Load methods and overload Save methods.
These methods enable us to work with a physical file (when providing a file's path) or with
an in-memory file (when providing a file's stream).
C# code
DocumentModel document;
VB.NET code
Dim document As DocumentModel
Also, among the GemBox.Document's overload Save methods there are some that take an
object type as the first parameter. These methods are used for direct streaming of an
output file to the web application's client. This object parameter can be of the
System.Web.HttpResponse or System.Web.HttpResponseBase type; note that this
parameter is by design of an object type in order to avoid GemBox.Document's dependency
with System.Web assembly.
Here is an example of streaming a file to the client's browser in ASP.NET Web Forms
application:
C# code
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{}
document.Sections.Add(
new Section(document,
new Paragraph(document, "Hello World!")));
document.Save(this.Response, "Output.docx");
}
}
VB.NET code
Public Class _Default
Inherits Page
document.Sections.Add( _
New Section(document, _
New Paragraph(document, "Hello World!")))
document.Save(Me.Response, "Output.docx")
End Sub
End Class
C# code
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
document.Sections.Add(
new Section(document,
new Paragraph(document, "Hello World!")));
document.Save(this.Response, "Output.docx");
}
}
VB.NET code
Public Class HomeController
Inherits Controller
Sub Download()
Dim document = New DocumentModel()
document.Sections.Add( _
New Section(document, _
New Paragraph(document, "Hello World!")))
document.Save(Me.Response, "Output.docx")
End Sub
End Class