我一直在嘗試使用可以下載到Android設備上的ASP.NET(C#)生成電子名片。生成可以使用ASP.NET在Android上下載的電子名片
生成卡的過程非常簡單,所以我並不太擔心。這是下載本身,我無法工作。
我對電子名片附加到頁面響應代碼如下所示:
public void downloadCard()
{
//generate the vCard text
string vCard = generateCard();
//create the filename the user will download the file as
string filename = HttpUtility.UrlEncode(username + ".vcf", System.Text.Encoding.UTF8);
//get a reference to the response
HttpResponse response = HttpContext.Current.Response;
//clear the response and write our own one.
response.Clear();
response.ContentType = "text/x-vcard";
response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ";");
response.Write(vCard);
response.End();
}
我不會打擾顯示,因爲它不是真正重要的生成過程雖然頁面需要的唯一參數是用戶名這是通過一個RESFUL URL收到的,這要歸功於web.config文件中的一些URL重寫。因此,URL example.com/vcard/apbarratt會爲用戶apbarratt生成電子名片。
一個GET請求產生此代碼的響應如下所示:
200 OK
Date: Wed, 15 Aug 2012 13:49:56 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Disposition: attachment; filename=apbarratt.vcf;
Content-Length: 199
Server: Microsoft-IIS/7.5
Content-Type: text/x-vcard; charset=utf-8
Cache-Control: private
BEGIN:VCARD
VERSION:2.1
N;LANGUAGE=en-us:Andy Barratt
FN:Andy Barratt
TEL;CELL;VOICE:07000000000
URL;WORK:http://example.com
EMAIL;INTERNET:[email protected]
END:VCARD
這完全適用於每一個瀏覽器,我在(未iOS版已經測試過它,這是一個已經在解決了另一個問題另一種方式),除了Android股票瀏覽器。在這些瀏覽器中,下載失敗,無論是文件名「未知」和術語「失敗」,或在其他設備上使用用戶名「apbarratt.vcf」和術語「進行中」,似乎並未改變。
這個問題在其他瀏覽器如opera mobile/mini中不是問題。
我已經試過一切可能的事情我能想到的,讀書對我有整個事情的夢想類似的問題,所以許多博客......他們真的沉悶。
無論如何,希望有一些新鮮的眼睛能夠幫助我。也許有人已經做到了,可以分享一些代碼,期待一些幫助。
安迪
這可能是相關的:http://stackoverflow.com/questions/4381766/how-to-get-a-vcard-vcf-file-into-android-contacts-from-website。 – 2012-08-15 14:08:36