Close window after file transmit (ASP)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

This is partially a .NET question and partially scripting (whichever works :)

I recently wrote a vCard parser that sends vCards directly to the brower as a stream. After the file is transmitted I need to close the window, but I can't get anything to works because I’m ‘hijacking’ the Response.Write method.

Here is a small snippet of the code:

string strDN = "CN=Brigit Runge,OU=TestUsers,DC=engineering,DC=somewhere,DC=com";


DirectoryEntry deUser = new DirectoryEntry("LDAP://server/" + strDN);

string strCN = deUser.Properties["cn"].Value.ToString();
string strvCard = BuildvCard(deUser);

Response.AddHeader("content-disposition", string.Format("attachement; filename={0}.vcf", strCN));

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

Response.Write(strvCard);

Response.Write("<script>self.close();</script>");

//Response.End();

I've tried a number of script attempts, from onClick to onBlur. Any successful window closing prohibits the actual file transfer. I could use a timer, but I want to make sure the file actually gets sent.

Any ideas?

Thanks,
Bill
 
I decided the better way was to separate the functionality and make a second
page. I was using two pages anyway, a window with an iframe pointing to the
real window. It is possible to post back to a modal dialogue, but posting
back a file wasn't working. Instead of opening the save/open window, the
modal was going blank -- consequently I resorted to the iframe/modal hack.

The solution:
Open a second window that simply renders the vCard and then have the modal
close itself.

Remember that to get a modal to postback and close itself you must:

Set HTML/JScript:
<base target="_self">
window.opener = this.self;

C#:
Response.Write(string.Format("<script>window.open('vCardBuilder.aspx?adObject={0}&action=browser');self.close();</script>", strPath));

Now I need to figure out how to parse a photo into a vCard, it sounds easy
but I keep crashing Outlook *evil grin*

Bill
 
Back
Top