For your ideas, first I give you some opinions about uploading word and saving word as Pdf.
Comments are all in the code.
protected void btnUpload_Click(object sender, EventArgs e)
{
//【1】Determine whether the file exists
if (!this.ful.HasFile) return;
//【2】Get the file size and determine whether it meets the setting requirements (becomes MB)
double fileLength = this.ful.FileContent.Length / (1024.0 * 1024.0);
//Gets the limit on the size of the uploaded file in the configuration file
double limitedLength = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["PhysicsObjectLength"]);
limitedLength = limitedLength / 1024.0;//Convert to MB units
//Determine whether the actual file size meets the requirements
if (fileLength > limitedLength)
{
// this.ltaMsg.Text = "The upload file size cannot be exceeded" + limitedLength + "MB";
this.ltaMsg.Text = "<script type='text/javascript'>alert('The upload file size cannot be exceeded" + limitedLength + "M')</script>";
return;
}
//【3】Obtain the file name and determine whether the file extension meets the requirements
string fileName = this.ful.FileName;
if (fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower() == "exe")
{
this.ltaMsg.Text = "<script type='text/javascript'>alert('The uploaded file cannot be an exe file')</script>";
return;
}
fileName = DateTime.Now.ToString("yyyyMMddhhssms") + "_" + fileName;
string path = "C:\\Users\\Administrator\\Desktop\\Test";
try
{
this.ful.SaveAs(path + "\\" + fileName);
this.ltaMsg.Text = "<script type='text/javascript'>alert('Success!')</script>";
}
catch (Exception ex)
{
this.ltaMsg.Text = "<script type='text/javascript'>alert('Fail!" + ex.Message + "')</script>";
}
}
protected void SaveAsPDF_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
Document document = null;
application.Visible = false;
// open docx file
document = application.Documents.Open("C:\\Users\\Administrator\\Desktop\\Test\\WordTest.docx");
// convert to pdf file
document.ExportAsFixedFormat("C:\\Users\\Administrator\\Desktop\\Test\\WordTest.pdf", WdExportFormat.wdExportFormatPDF);
document.Close();
}
<form id="form1" runat="server">
<div>
Please select the file you want to upload:<asp:FileUpload ID="ful" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
<br />
<br />
<asp:Literal ID="ltaMsg" runat="server"></asp:Literal>
</div>
<div>
SaveAsPDF: <asp:Button ID="SaveAsPDF" runat="server" Text="SaveAsPDF" OnClick="SaveAsPDF_Click" />
</div>
</form>
output:
As for your online modification of Word this design, I can give you the following suggestions:
- Rich text editor
- In Internet Explorer, edit office documents in the browser. 3.Use some APIs and some other products, such as: Office Web Apps Server.
Best Regards
Qi You
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.