0

我已经从 asp.net + c# 应用程序生成了 vCard。在结束时。浏览器弹出“使用/另存为打开”框。我不想出现这个框。而不是那个,我想直接将生成的.vcf文件设置为用outlook 2007或03打开。怎么办?我的代码是:

小号

ystem.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            //vCard Begin
            stringWrite.WriteLine("BEGIN:VCARD");
            stringWrite.WriteLine("VERSION:2.1");
            //Name
            stringWrite.WriteLine("N:" + nameLast + ";" + nameFirst +
                                  ";" + nameMiddle + ";" + nameTitle);
            //Full Name
            stringWrite.WriteLine("FN:" + nameFirst + " " +
                                  nameMiddle + " " + nameLast);
            //Organisation
            stringWrite.WriteLine("ORG:" + company + ";" + department);
            //URL
            stringWrite.WriteLine("URL;WORK:" + uRL);
            //Title
            stringWrite.WriteLine("TITLE:" + title);
            //Profession
            stringWrite.WriteLine("ROLE:" + profession);
            //Telephone
            stringWrite.WriteLine("TEL;WORK;VOICE:" + telephone);
            //Fax
            stringWrite.WriteLine("TEL;WORK;FAX:" + fax);
            //Mobile
            stringWrite.WriteLine("TEL;CELL;VOICE:" + mobile);
            //Email
            stringWrite.WriteLine("EMAIL;PREF;INTERNET:" + email);
            //Address
            stringWrite.WriteLine("ADR;WORK;ENCODING=QUOTED-PRINTABLE:" + ";" +
                                  office + ";" + addressTitle + "=0D" +
                                  streetName + ";" + city + ";" +
                                  region + 

";" + postCode + ";" + country);

        //Revision Date
        //Not needed
        //stringWrite.WriteLine("REV:" + DateTime.Today.Year.ToString() +
        //            DateTime.Today.Month.ToString() + DateTime.Today.Day.ToString() + "T" +
        //            DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + 
        //            DateTime.Now.Second.ToString() + "Z");
        //vCard End
        stringWrite.WriteLine("END:VCARD");
        response.Write(stringWrite.ToString());
        response.AppendHeader("Hi", "PMTS");
        response.End();
4

1 回答 1

0

如果我对您的理解正确,那么问题是当您的意思是让 vCard 简单地从网络打开时,您会得到一个运行或下载对话框。

假设这实际上是您想要的,我相信您只需将您的响应设置为 vCard MIME 类型之一(text/x-vcardtext/directory;profile=vCardtext/directory)。

Response.ContentType = "text/x-vcard";

我希望这会有所帮助。

- 编辑 -

使用以下代码,在 Internet Exploder 中正确提示我打开或保存(并打开在 Outlook 中打开文件)。不幸的是,Chrome 似乎仍然不支持打开文件,因此似乎有一个永久的下载框。在 IE 中尝试以下代码,您就会明白我的意思;有用。此外,附带说明 - 如果格式正确,我将能够更容易地复制您的代码。您是否有机会编辑您的帖子、突出显示代码并点击“101010”图标?非常感谢,祝你好运!

using System;
using System.IO;
using System.Web.UI;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        private string nameLast = "May";
        private string nameFirst = "Lance";
        private string nameMiddle = "R.";
        private string nameTitle = "Mr.";
        private string company = "CoreLogic";
        private string department = "Development";
        private string uRL = "http://www.lancemay.com";
        private string title = "Application Developer Senior";
        private string profession = "Developer";
        private string telephone = "(123) 555-1212";
        private string fax = "(321) 555-1212";
        private string mobile = "(555) 555-1212";
        private string email = "lancemay@gmail.com";
        private string office = "Louisville";
        private string addressTitle = "";
        private string streetName = "123 Easy St.";
        private string city = "Louisville";
        private string region = "KY";
        private string postCode = "40223";
        private string country = "US";
        protected void Page_Load(object sender, EventArgs e)
        {
            StringWriter stringWrite = new StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            //vCard Begin
            stringWrite.WriteLine("BEGIN:VCARD");
            stringWrite.WriteLine("VERSION:2.1");
            //Name
            stringWrite.WriteLine("N:" + nameLast + ";" + nameFirst + ";" + nameMiddle + ";" + nameTitle);
            //Full Name
            stringWrite.WriteLine("FN:" + nameFirst + " " + nameMiddle + " " + nameLast);
            //Organisation
            stringWrite.WriteLine("ORG:" + company + ";" + department);
            //URL
            stringWrite.WriteLine("URL;WORK:" + uRL);
            //Title
            stringWrite.WriteLine("TITLE:" + title);
            //Profession
            stringWrite.WriteLine("ROLE:" + profession);
            //Telephone
            stringWrite.WriteLine("TEL;WORK;VOICE:" + telephone);
            //Fax
            stringWrite.WriteLine("TEL;WORK;FAX:" + fax);
            //Mobile
            stringWrite.WriteLine("TEL;CELL;VOICE:" + mobile);
            //Email
            stringWrite.WriteLine("EMAIL;PREF;INTERNET:" + email);
            //Address
            stringWrite.WriteLine("ADR;WORK;ENCODING=QUOTED-PRINTABLE:" + ";" + office + ";" + addressTitle + "=0D" + streetName + ";" + city + ";" + region + ";" + postCode + ";" + country);

            stringWrite.WriteLine("END:VCARD");
            Response.ContentType = "text/x-vcard";
            Response.Write(stringWrite.ToString());
            Response.AppendHeader("Hi", "PMTS");
            Response.End();
        }
    }
}
于 2010-06-30T13:36:30.640 回答