EDraw
WebOffice Component provides some
methods to upload the file to a web
server.
HTTP Post
[id(36), helpstring(”Initializes the
HTTP connection.”)]
boolean HttpInit();
[id(37), helpstring(”Adds the post
parameter.”)]
boolean HttpAddpostString([in] BSTR
Name, [in] BSTR Value);
[id(38), helpstring(”Adds the post
file.”)]
boolean HttpAddPostFile([in] BSTR
LocalFilePath, [in] BSTR NewFileName);
[id(39), helpstring(”Executes the post
action.”)]
boolean HttpPost([in] BSTR WebUrl,[in,
optional] VARIANT WebUsername, [in,
optional] VARIANT WebPassword);
You can use the follow steps to save the
opened office document to a web server.
Sub SavetoServer()
‘ASP.NET’
OA1.HttpInit
OA1.HttpAddpostString “author”,
“anyname”
OA1.HttpAddpostString “Data”,
“2007-5-15″
OA1.HttpAddPostFile “”,
“newfilename.doc”
OA1.HttpPost
“http://localhost:1320/Samples/UploadAction.aspx“
‘Or you can call the Save method to
upload the openned file to the server
directly.For examples:
‘OA1.Save
“http://localhost:1320/Samples/UploadAction.aspx?FileName=newname”
End Sub
Note: If the first parameter of
“HttpAddPostFile” is blank, the method
will upload the opened office file to
server.
Then you need to write a ASP.NET Get
page to receipt the file.
Review the follow examples:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;
public partial class UploadAction :
System.Web.UI.Page
{
protected void Page_Load(object sender,
EventArgs e)
{
if (Request.Params[”author”] ==
“anyname” && Request.Params[”Data”] ==
“2007-5-15″)
{
Response.Write(”0\n”);
Response.Write(”We have receipted the
right param from Office ActiveX
Control.”);
}
if (Request.Files.Count == 0)
{
Response.Write(”0\n”);
Response.Write(”There isn’t file to
upload.”);
Response.End();
}
if (Request.Files[0].ContentLength == 0)
{
Response.Write(”0\n”);
Response.Write(”Failed to receipt the
data.\n\n”);
Response.End();
}
string fullFileName =
Server.MapPath(Request.Files[0].FileName);
Request.Files[0].SaveAs(fullFileName);
Response.Write(”Upload Successfully.”);
Response.End();
}
}
|
Upload a file to a Web server in ASP.NET |
| |||||||||||||||||
