Hi @Gani_tpt,
My problem is, i am already developing software like uploading single document.
You can simply merge two uploaded single documents. The following code implements doc1, and doc2 is implemented in the same way.
If you need to display the information in page2.aspx, you only need to save the information in page1.aspx, and then page2 gets the information from the database.
To view Word documents on ASP.NET pages, you need to use the Microsoft.Office.Interop.Word dll.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function clear() {
//Reference the FileUpload and get its Id and Name.
var fileUpload = $("[id*=FileUpload1]");
var id = fileUpload.attr("id");
var name = fileUpload.attr("name");
//Create a new FileUpload element.
var newFileUpload = $("<input type = 'file' />");
//Append it next to the original FileUpload.
fileUpload.after(newFileUpload);
//Remove the original FileUpload.
fileUpload.remove();
//Set the Id and Name to the new FileUpload.
newFileUpload.attr("id", id);
newFileUpload.attr("name", name);
return false;
};
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button Text="Upload" runat="server" OnClick="Upload" />
<asp:Button ID="btnClear" Text="Clear" runat="server" OnClick="clear" OnClientClick="clear()" />
<div id="dvWord" runat="server"></div>
</form>
</body>
</html>
protected void Upload(object sender, EventArgs e)
{
object documentFormat = 8;
string randomName = DateTime.Now.Ticks.ToString();
object htmlFilePath = Server.MapPath("~/Temp/") + randomName + ".htm";
//string directoryPath = Server.MapPath("~/Temp/") + randomName + "_files";
object fileSavePath = Server.MapPath("~/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName);
//If Directory not present, create it.
if (!Directory.Exists(Server.MapPath("~/Temp/")))
{
Directory.CreateDirectory(Server.MapPath("~/Temp/"));
}
//Upload the word document and save to Temp folder.
FileUpload1.PostedFile.SaveAs(fileSavePath.ToString());
//Open the word document in background.
_Application applicationclass = new Microsoft.Office.Interop.Word.Application();
applicationclass.Documents.Open(ref fileSavePath);
applicationclass.Visible = false;
Document document = applicationclass.ActiveDocument;
//Save the word document as HTML file.
document.SaveAs(ref htmlFilePath, ref documentFormat);
//Close the word document.
document.Close();
//Read the saved Html File.
string wordHTML = System.IO.File.ReadAllText(htmlFilePath.ToString());
//Loop and replace the Image Path.
foreach (Match match in Regex.Matches(wordHTML, "<v:imagedata.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase))
{
wordHTML = Regex.Replace(wordHTML, match.Groups[1].Value, "Temp/" + match.Groups[1].Value);
}
//Delete the Uploaded Word File.
File.Delete(fileSavePath.ToString());
File.Delete(htmlFilePath.ToString());
dvWord.InnerHtml = wordHTML;
}
protected void clear(object sender, EventArgs e)
{
dvWord.InnerHtml = "";
}
Best regards,
Lan Huang
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.