Nehad Tarek
Nehad Tarek

Reputation: 11

how to upload mp3 file using asp.net c#

I want to upload mp3 file using file uploader and I don't want to save it in the database I used server.mappath

if (FileUploadsong.HasFiles)
    {
      FileUploadsong.PostedFile.SaveAs(Server.MapPath("songs" + "/" + Txtsongname + "~/mp3file/"));
        byte[] mp3file = System.IO.File.ReadAllBytes("songs");
    }

but I got this error:

path error

Upvotes: 0

Views: 811

Answers (1)

Marco
Marco

Reputation: 23937

The error tells you that you path name is invalid and cannot be found. That is, because you are using the control itself as part of your path, instead of its .Text property:

if (FileUploadsong.HasFiles)
{
    FileUploadsong.PostedFile.SaveAs(Server.MapPath("songs" + "/" + Txtsongname.Text + "/mp3file/"));
    byte[] mp3file = System.IO.File.ReadAllBytes("songs");
}

And please, post your errors as text, not as an image. Screenreaders cannot interpret images and if the image does get deleted, so does your error message for everyone.

Upvotes: 4

Related Questions