AceoffixCtrlOpenDocument Method |
Namespace: Aceoffix
public void OpenDocument( string DocumentURL, OpenModeType OpenMode, string UserName )
The URL of the document which is going to be opened.
The document can be a file from Web folder and also can be a binary stream outputted by server page. However, the document must be Office document format.
Aceoffix supports many document formats, such as *.doc,*.docx,*.xls,*.xlsx,*.ppt,*.pptx,*.vsd and *.mpp.
![]() |
---|
The URL can be a relative URL or a complete URL which starts with "http". The relative URL can be relative to the URL of current page and it also can be a root relative URL.
The root relative URL starting with "/" is relative to the root path of the application. New feature: The URL can be the physical disk path of the document file on the server. For example: D:\docfiles\test.doc.
Note: If the URL is a complete URL, make sure that this URL must link to the current website instead of other websites. It is recommended that you use a relative URL to make the application more portable. |
This is the important method of AceoffixCtrl. It is used to open an Office document online.
The OpenDocument method should be called at the end of code in Load.
Code example 1: Open the test.doc document and set the document in editable state.
Refer to the full code example in the Load event topic to learn how to open document online.
AceoffixCtrl1.OpenDocument("doc/test.doc", Aceoffix.OpenModeType.docNormalEdit, "John Scott");
Code example 2: The document which is going to be opened is a binary stream outputted by docstream.aspx page.
AceoffixCtrl1.ServerPage = "aceoffix-runtime/server.aspx"; AceoffixCtrl1.SaveFilePage = "savefiledb.aspx?id=1"; AceoffixCtrl1.OpenDocument("docstream.aspx?id=1", Aceoffix.OpenModeType.docNormalEdit, "John Scott");
The following code is the source code of docstream.aspx.
protected void Page_Load(object sender, EventArgs e) { string strID = Request.QueryString["id"]; if (strID == null) return; Response.Clear(); // Required Response.ContentType = "application/msword"; // Required Response.AddHeader("Content-Disposition", "attachment; filename=down.doc"); // Required string connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|demo.mdb"; OleDbConnection conn = new OleDbConnection(connstring); conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = "select FileBin from documents where ID = @id"; OleDbParameter spID = new OleDbParameter("@id", OleDbType.Integer); spID.Value = strID; cmd.Parameters.Add(spID); OleDbDataReader dr = cmd.ExecuteReader(); int iFileSize = 0; if (dr.Read()) { int FileCol = 0; // the column # of the BLOB field Byte[] b = new Byte[(dr.GetBytes(FileCol, 0, null, 0, int.MaxValue))]; dr.GetBytes(FileCol, 0, b, 0, b.Length); iFileSize = b.Length; System.IO.Stream fs = Response.OutputStream; fs.Write(b, 0, b.Length); fs.Close(); } dr.Close(); conn.Close(); Response.AppendHeader("Content-Length", iFileSize.ToString()); // Required Response.End(); // Required }
Refer to the code example in the FileBytes method topic to view the code of savefiledb.aspx page.