Edit word document and save .net

Ajay Kalidindi 41 Reputation points
2023-05-08T12:55:26.3466667+00:00

Hi,

I need to upload word document and show content of word document in Editor and update the modified document.

Also option to save word document to Pdf.

For this scenario what tool can I use? I have used some third party tools to convert word document data to html and showed in editor but content is not showing perfectly.

Please give me suggestion.

Thanks,

Ajay.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,650 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,419 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,651 questions
0 comments No comments
{count} votes

Accepted answer
  1. QiYou-MSFT 4,311 Reputation points Microsoft Vendor
    2023-05-09T07:53:05.4+00:00

    Hi @Ajay Kalidindi

    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" />
             &nbsp;&nbsp;
             <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:

    FileUpLoad1

    FileUpLoad2

    As for your online modification of Word this design, I can give you the following suggestions:

    1. Rich text editor
    2. 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.


0 additional answers

Sort by: Most helpful