EdgeDoc
Features
Tech Specs
How-to C#
Pricing
ASP.NET Open Server File on Web Browser
  |  
Home ›› ASP.NET Document Viewer ›› C#: ASP.NET Document Viewer ›› C# Open a File Inside the Server

C# HTML5 Viewer: Open a File Inside the Server


How to Load a File Inside the Server to View on C# Web Project Document Viewer






RasterEdge.Xdoc.HTML5Viewer.dll also provides a mature .NET API for opening file inside server to your C# project document viewer to view. This function can be realized by adding ?file=filePath to browser address bar and your file path can be a relative or absolute path. For example, use ".../?file=/RasterEdge_Demo_Docs/pdf/demo_1.pdf", you will open the demo_1.pdf in pdf folder under RasterEdge_demo_Docs folder. Or you can use an absolute file path to open file, like ".../?file=c:/test/demo.pdf".




HTML5 Viewer in C#: Open a File Inside Server



RasterEdge .NET document viewer control allows C# programmers to add and set the function of file opening from server on their own HTML5 document viewers. And it's very easy to implement this function by copying the following sample code to your web project Default.aspx.cs. In this example, CreateWebDocFromServer(string path); API is used to return a REWebDocument object. Parameter path is the absolute path of file on server.




public void LoadFileFromUrl()
{
        string file = Request.QueryString["file"];
        string src = Request.QueryString["src"];
        if (file != null && file != "")
                LoadFileFromCustomizedUrl(file);
        else if (src != null && src != "")
                LoadFileFromPublicAccessibleUrl(src);
}

public void LoadFileFromCustomizedUrl(string file)
{
        string path = REDocumentControl.GetAbsolutePath(file);
        REWebDocument webDoc = REDocumentControl.CreateWebDocFromServer(path);
        MsgToClient = webDoc.MsgToClient;
}