×

Discussion Board

Results 1 to 7 of 7

Hybrid View

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    Arrow mp3 file download as .aspx file and not open on phone player

    Hi

    I have developed one wap page using Microsoft Mobile control form in .net in c#.
    On click of button, i need to download the mp3 file into cell phone. Its downloaded successfully to my cell phone. But open in the web page rather then in real player of my cell phone Nokia N 72. When I access the same page from Internet Browser like Mozilla, IE etc. then file save successfully and played in player.

    For more Detail, i ma putting my code also.

    protected void CmdDownload_Click(object sender, EventArgs e)
    {
    try
    {
    string originalFilename = strFileName;
    string localfilename = Server.MapPath("~/RingtoneFiles") + "/" + strFileName;
    ////////////////////////////////////////////////////////////////////////////
    WebClient req = new WebClient();
    CredentialCache mycache = new CredentialCache();
    mycache.Add(new Uri(localfilename), "Basic", new NetworkCredential("administrator", "admin$123"));
    req.Credentials = mycache;
    HttpResponse response = HttpContext.Current.Response;
    response.Clear();
    response.ClearContent();
    response.ClearHeaders();
    response.Buffer = true;
    response.AddHeader("Content-Disposition", "attachment;filename=\"" + originalFilename + "\"");
    byte[] data = req.DownloadData(localfilename);
    response.BinaryWrite(data);
    response.End();
    return;
    }
    catch (Exception ex)
    {
    if (ex.Message == "The remote server returned an error: (404) Not Found.")
    throw new Exception("File not found");
    else if (ex.Message == "The remote server returned an error: (401) Unauthorized.")
    throw new Exception("Unauthorized access");
    return;
    }
    }


    Anyone can help me or can provide any sample code or link for solving my problem. I will be very greatfull to you.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: mp3 file download as .aspx file and not open on phone player

    PCs often recognise the downloaded file purely from the extension. If you want the mp3 file to be recognised by your phone on download then you need to serve it to the phone with the correct MIME type.

    If there isn't a MIME type but you save the file and then open it on the phone it should work fine though.

    Sorcery

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    Re: mp3 file download as .aspx file and not open on phone player

    thanks for response.
    where we have to write the content type in the code.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    Re: mp3 file download as .aspx file and not open on phone player

    we have add the content type in the code and find that it save and displayed as wapauthenticate.aspx not as <filename>.mp3, opened by the media player after downloading?

    string Name = dsDownload.Tables[0].Rows[0]["RingtoneFileName"].ToString();
    string Format = dsDownload.Tables[0].Rows[0]["RingtoneFileFormat"].ToString();
    string strFileName = Name + "." + Format;

    //THIS CODE IS WRITTEN TO INCREMENT THE NO OF COUNT IN THE DATABASE
    //IncrementFileDownloadCount(RingtoneID);
    //CODE END
    string originalFilename = strFileName;
    string localfilename = Server.MapPath("~/RingtoneFiles") + "/" + strFileName;
    WebClient req = new WebClient();
    CredentialCache mycache = new CredentialCache();
    mycache.Add(new Uri(localfilename), "Basic", new NetworkCredential("administrator", "admin$123"));
    req.Credentials = mycache;
    HttpResponse response = HttpContext.Current.Response;
    response.Clear();
    response.ClearContent();
    response.ClearHeaders();
    response.Buffer = true;
    response.AddHeader("Content-Disposition", "attachment;filename=\"" + originalFilename + "\"");
    Response.AddHeader("Content-Type", "audio/mpeg");
    byte[] data = req.DownloadData(localfilename);
    response.BinaryWrite(data);
    response.End();
    return;

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: mp3 file download as .aspx file and not open on phone player

    Sorry, I answered your last post in a bit of a hurry, assuming I'd seen the same problem before.

    It looks to me like you have some code which is supposed to run server side when you select a link and that code is being downloaded to the phone rather than the mp3 file, is that the case? Or is the mp3 file actually being downloaded but with the wrong name?

    Definitely looks like a server side problem though.

    Sorcery

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    Re: mp3 file download as .aspx file and not open on phone player

    thanks for response. what will happen with that case.
    you are correct. on the click of button we are running server side code.
    the result is following
    1. file is downloaded to cell phone successfully.
    2. its open in cell player like real player.
    3. name of file display as <page name>.aspx not <file name>.mp3.
    4. downloaded file is mp3 because we have tested this as follows
    i. I connect my cell phone to pc via cable.
    ii. I change the file extention .aspx-> .mp3.
    iii. Now file start to play in pc and as well as in cell phone. And now its visible in cell phone also.

    So it means that downloaded file is mp3 not an page. only its name become <page name>.aspx. So its not played by real player of cell phone initially.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: mp3 file download as .aspx file and not open on phone player

    Sorry, all I can say is that it's extremely unlikely that the phone is changing the name and type of the file sent to it!

    I don't really have much experience setting up the server side, perhaps someone else can help.


    Sorcery

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •