Как создать doc-файл в папке сервера с помощью ASP.NET с#
привет команда,
я хочу творить .doc-файлы в папке сервера.
у нас есть один сервер 101.20.123.11, на котором мы установили sql server.
мое требование заключается в том, что у меня есть одна страница, на которой заполните поля и нажмите кнопку Отправить .всякий раз, когда я нажимаю на кнопку Отправить, мне нужно создать файл word вместе с этими полями данных в нашей папке сервера, а также мне нужно отправить почту в качестве вложения этого файла doc через базу данных.
записка:
на этой странице Я не использую элемент управления fileupload.
пожалуйста помочь.
Что я уже пробовал:
protected void btnSubmit_click(object sender,EventArgs e) { try { string FilePathSave = ""; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset = ""; HttpContext.Current.Response.ContentType = "application/msword"; string strFileName = string.Empty; strFileName = "ServiceAttachApprovalDocument-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc"; HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName); StringBuilder strHTMLContent = new StringBuilder(); strHTMLContent.Append("<img src='" + @"D:\CSS Projects\Inventory_VSS_04-May-2017\ImagingTOOL\images\kodac1.png'>".ToString()); // strHTMLContent.Append("< img src = '~/images/kodac.png' visible = 'true' runat = 'server' style = 'width: 75px; height: 41px' />".ToString()); //strHTMLContent.Append("<br>".ToString()); strHTMLContent.Append(" <h1 title='Heading' align='Center' style='font-family:verdana;font-size:100%;background:#C0C0C0'>SERVICE ATTACH APPROVAL FORM </h1>".ToString()); strHTMLContent.Append("<br>".ToString()); strHTMLContent.Append("<table width='100%' border='2'>".ToString()); //strHTMLContent.Append("<tr>".ToString()); //strHTMLContent.Append("<td style='width: 100px;background:#99CC00'>SERVICE ATTACH APPROVAL FORM</td>".ToString()); //strHTMLContent.Append("</tr><br/>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td colspan='2'>Name of End User </td>".ToString()); strHTMLContent.Append("<td>"+txtEndusername.Text+"</td>".ToString()); strHTMLContent.Append("<td>Name of Reseller</td>".ToString()); strHTMLContent.Append("<td>" + txtResellerName.Text + "</td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td>Name of Distributor </td>".ToString()); strHTMLContent.Append("<td colspan='4'>" + txtDistributorName.Text + "</td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td>Cat No</td>".ToString()); strHTMLContent.Append("<td>Model </td>".ToString()); strHTMLContent.Append("<td> Total Quantity </td>".ToString()); strHTMLContent.Append("<td> Total Period including Standard One year </td>".ToString()); strHTMLContent.Append("<td> Name of nearest Competitor offering Service Attach </td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td>"+ddlproduct.SelectedItem.Text+"</td>".ToString()); strHTMLContent.Append("<td>" + ddlproduct.SelectedItem.Text + "</td>".ToString()); strHTMLContent.Append("<td> "+txtQuantity.Text+" </td>".ToString()); strHTMLContent.Append("<td>"+txtperiodStdYear.Text+"</td>".ToString()); strHTMLContent.Append("<td>"+txtCompetitorname.Text+"</td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td colspan='2'></td>".ToString()); strHTMLContent.Append("<td>Distributor Price(INR) </ td>".ToString()); strHTMLContent.Append("<td> Reseller Price(INR)</ td>".ToString()); strHTMLContent.Append("<td> End User Price(INR) </ td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td colspan='2'>Unit Product Sales Price Without Discount</td>".ToString()); strHTMLContent.Append("<td>"+txtUPSWOutdcntDistributorprice.Text+"</ td>".ToString()); strHTMLContent.Append("<td> " + txtUPSWOutdcntResellerPrice.Text + "</ td>".ToString()); strHTMLContent.Append("<td>" + txtUPSWOutdcntEndUserPrice.Text + "</ td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td colspan='2'>Unit Product Sales Price With Discount</td>".ToString()); strHTMLContent.Append("<td>" + txtUPSWithdcntDistributorprice.Text + "</ td>".ToString()); strHTMLContent.Append("<td> " + txtUPSWithdcntResellerPrice.Text + "</ td>".ToString()); strHTMLContent.Append("<td>" + txtUPSWithdcntEndUserPrice.Text + "</ td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td colspan='2'>Unit Service Attach Without Discount</td>".ToString()); strHTMLContent.Append("<td>" + txtUSAWOutdcntDistributorprice.Text + "</ td>".ToString()); strHTMLContent.Append("<td> " + txtUSAWOutdcntResellerPrice.Text + "</ td>".ToString()); strHTMLContent.Append("<td>" + txtUSAWOutdcntEndUserPrice.Text + "</ td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td colspan='2'>Service Attach With Discount</td>".ToString()); strHTMLContent.Append("<td>" + txtUSAWithdcntDistributorprice.Text + "</ td>".ToString()); strHTMLContent.Append("<td> " + txtUSAWithdcntResellerPrice.Text + "</ td>".ToString()); strHTMLContent.Append("<td>" + txtUSAWithdcntEndUserPrice.Text + "</ td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("</table>".ToString()); strHTMLContent.Append("<br>".ToString()); DateTime WDate = Convert.ToDateTime(System.DateTime.Now.ToShortDateString()); string WarrentyDate = WDate.ToString("dd/MM/yyyy"); strHTMLContent.Append(" Above prices valid for Warranty until (dd/mm/yyyy) :"+ WarrentyDate); strHTMLContent.Append("<br>".ToString()); strHTMLContent.Append("<br>".ToString()); strHTMLContent.Append("<table border='2' width='100%'>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td>Name</td>".ToString()); strHTMLContent.Append("<td>(Sales Manager)</ td>".ToString()); strHTMLContent.Append("<td>(Service Manager)</ td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td>Signature</td>".ToString()); strHTMLContent.Append("<td></td>".ToString()); strHTMLContent.Append("<td></td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("<tr>".ToString()); strHTMLContent.Append("<td>Date</td>".ToString()); strHTMLContent.Append("<td></td>".ToString()); strHTMLContent.Append("<td></td>".ToString()); strHTMLContent.Append("</tr>".ToString()); strHTMLContent.Append("</table>".ToString()); strHTMLContent.Append("<br><br>".ToString()); strHTMLContent.Append("<p align='Center'> Note : This is dynamically generated word document </p>".ToString()); //StreamWriter sw = File.CreateText(MapPath("myFile.txt")); //sw.WriteLine( txtFile.Text ); //sw.Close(); // Convert to string string strFileData = strHTMLContent.ToString(); string strFolderValue = @"\101.20.123.11\c:\";//this is server path // string strFolderValue = @"D:\CSS Projects\Inventory_VSS_04-May-2017\ImagingTOOL\Word\"; //local path.. //System.IO. DirectoryInfo Folder = new DirectoryInfo(strFolderValue); //objprop.P_SAFilename = strFileName; //objprop.P_SAFilepath = strFolderValue.ToString() + strFileName.ToString(); string SAFilename = strFileName; string SAFilePath= strFolderValue.ToString() + strFileName.ToString(); if (Folder.Exists) { if (strFileData != string.Empty) { // build the path FilePathSave = Folder.ToString() + strFileName; // if file exist delete and then save again // else save file File.WriteAllText(FilePathSave, strFileData); // is supposed to overwrite the file if it is there but doesn't } else { Response.Write("(Nothing to save)"); } // If we can't find the folder } else { Response.Write("Folder [" + strFolderValue + "not found]"); } BindProperties(); int i= objpo.InsertServiceAttachApproval(objprop, SAFilename, SAFilePath); if(i>0) { lblMsg.Text = "Inserted succesfully."; objpo.MAIL_FOR_ServiceAttchApprovalForDocFile(); Clear(); } } catch (Exception ex) { throw; } }