views:

25

answers:

1

Hi, I have generated the the vCard from asp.net + c# application. While ending up. browsers pops up for "open with /Save as" box. I don't want to appear this box. rather than that , I want to directly set the generated .vcf file to open with outlook 2007 or 03. what hae to do ? My code is:

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);

        //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();
A: 

If I'm understanding you correctly, the issue is that you're getting a run-or-download dialog when you mean for the vCard to simply open from the web.

Assuming that is actually what you're wanting, I believe you need only to set your response to one of the vCard MIME types (text/x-vcard, text/directory;profile=vCard, or text/directory).

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

I hope that helps.

- EDIT -

Using the following code, I am properly prompted to Open or Save (and Open opens the file in Outlook) in Internet Exploder. Unfortunately, Chrome still does not support opening files it seems, and so there is a download box somewhat permanently it seems. Try the following code out in IE and you'll see what I mean; it works. Also, on a side note - I would have been able to replicate your code somewhat easier if properly formatted. Any chance you can edit your post, highlight the code, and hit the "101010" icon? Thanks much, and good luck!

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 = "[email protected]";
        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();
        }
    }
}
Lance May
yes, you perfectly got my question. But i used these mimes.but not working Lance. can you please tell or ask somebody for this.please.I just want to avoid that "run-or-download dialog" box. and want to inbuilt (by c# code) set to generated .vcf file as outlook.
Lalit
@Lalit: After re-reading your comment, it looks like you're wanting to do something that you cannot. You can't force the execution of anything sometimes (Google Chrome), and the times you can, the browser still gets the say; not the server (the server can only ever make the suggestion, which setting the MIME type does).
Lance May