简体   繁体   English

使用JavaScript在C#中使用邮件附件在客户端计算机上获取服务器端导出的Crystal报表路径

[英]Get server side exported crystal report path on client machine using javascript for mail attachment in c#

hi below is my javascript code for opening default outlook. 您好,以下是我的JavaScript代码,用于打开默认Outlook。

<script language="javascript" type="text/javascript">
    function SendAttach() {
        var theApp //Reference to Outlook.Application 
        var theMailItem //Outlook.mailItem
        var attach3 = '<%= Session["MyFilePath"].ToString() %>'
        var recipient
        var subject = "Report Document"
        var msg = "Please Find Attached File \n\n" + "Thanks & Regards \n" + '<%=  Session["USER"].ToString() %>'
        try {
            var theApp = new ActiveXObject("Outlook.Application");
            var objNS = theApp.GetNameSpace('MAPI');
            var theMailItem = theApp.CreateItem(0) // value 0 = MailItem

            theMailItem.Subject = (subject);
            theMailItem.Body = (msg);
            theMailItem.Attachments.add(attach3);
            theMailItem.display();
        } catch (err) {
            alert("The following may have cause this error: \n" + "1. The Outlook express 2003 is not installed on the machine.\n" + "2. The msoutl.olb is not availabe at the location " + "C:\\Program Files\\Microsoft Office\\OFFICE11\\msoutl.old on client's machine " + "due to bad installation of the office 2003." + "Re-Install office2003 with default settings.\n" + "3. The Initialize and Scripts ActiveX controls not marked as safe is not set to enable.")

        }

    }
</script>

in this <%= Session["MyFilePath"].ToString() %> is passed by server side code. 服务器端代码传递此<%= Session["MyFilePath"].ToString() %>内容。 MyFilePath is path of my file which i am attaching as an attachment in outlook. MyFilePath是我作为Outlook中的附件附加的文件的路径。 this working fine on server side but when i run on client side this file path is not attaching attachment which is on server side. 这在服务器端工作正常,但是当我在客户端运行时,此文件路径未附加服务器端的附件。

below is my server side code. 下面是我的服务器端代码。

reportDocument = new ReportDocument();
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
reportDocument.Load(Server.MapPath("~/Boreports/Print_Lpo.rpt"));

Session["Rpt_Name"] = "Local_Purchase_Order_Rpt";
string Fname = "C://" + Session["Rpt_Name"].ToString() + ".pdf";

paramField = new ParameterField();
paramField.Name = "@LPONO";
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = Session["LPO_NO"].ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
reportDocument.SetParameterValue("@LPONO", paramDiscreteValue);

paramField = new ParameterField();
paramField.Name = "@REC_TYPE";
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = Session["ReportType1"].ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
reportDocument.SetParameterValue("@REC_TYPE", paramDiscreteValue);
// Session["param"] = paramFields;
//Session["reportdoc"] = "~/Boreports/Print_Lpo.rpt";
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.ReportSource = reportDocument;
reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, Fname);
Session["MyFilePath"] = Fname;

how i will get my serverside exported file on client machine?? 我如何在客户端计算机上获取服务器端导出的文件?

You can't access server side files from the client (unless the client happens to be running on the same machine as the server). 您无法从客户端访问服务器端文件(除非客户端恰巧与服务器在同一台计算机上运行)。

You will need to stream the file back to the client, or save it in a shared location. 您将需要将文件流式传输回客户端,或将其保存在共享位置。

Here's an example: http://aspadvice.com/blogs/rjdudley/archive/2005/03/14/2565.aspx 这是一个示例: http : //aspadvice.com/blogs/rjdudley/archive/2005/03/14/2565.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM