Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below is my code to convert audio files of any extension to .wav format.but what happens is if i am uploading 5 files at a time it only converts on files downloads and that file gets downloaded in my application folder or if i choose only one file for the first time it gets downloaded but without filename again if i am running the application the new file that we are taking doesn't gets downloaded.

C#
string fileName = string.Empty;
string savePath = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{

}

protected void UploadBtn_Click(object sender, EventArgs e)
{

    savePath = Server.MapPath(".") + "\\TempFiles\\";
    if (FileUpload1.HasFile)
    {
        fileName = Server.HtmlEncode(FileUpload1.FileName);
        string extension = System.IO.Path.GetExtension(fileName);

        if ((extension == ".DSS") || (extension == ".ds2") || (extension == ".dss") || (extension == ".WAV"))
        {
            ToWav(fileName, savePath);
            savePath += fileName;
            FileUpload1.SaveAs(savePath);
            UploadStatusLabel.Text = "Your file was uploaded successfully.";
        }
        else
        {
            UploadStatusLabel.Text = "Your file was not uploaded because " +
                                     "it does not have a .dss or .ds2 or .wav extension.";
        }

    }

}

static void ToWav(string filename, string path)
{
    using (DsReader dr = new DsReader(filename))
    {
        IntPtr format = dr.ReadFormat();
        using (WaveWriter ww = new WaveWriter(File.Create(path + ".wav"), AudioCompressionManager.FormatBytes(format)))
        {
            byte[] data = dr.ReadData();
            ww.WriteData(data);
        }
    }
}


What I have tried:

i had tried the above code which downloads only one file if we are selecting mutiple files also if we again run the application the file that was choosen second time doesn't gets downloaded with file names
Posted
Updated 2-Nov-16 0:30am
v2
Comments
Richard MacCutchan 2-Nov-16 6:33am    
Your code seems to be written to load only one file at a time. You need to capture all filenames and then repeat your processing for each one in the list.
Richard Deeming 2-Nov-16 10:34am    
You need to be clear about the difference between "download" and "upload".

"Download" means sending a file from the server to the client. The code you've posted is not doing this.

"Upload" means sending a file from the client to the server. This is what your code is doing.

Using the wrong term to describe what you're trying to do will only confuse people.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900