如何使用ASP .NET将所选文件转换为wav格式 [英] How to convert the selected files to wav format using ASP .NET
本文介绍了如何使用ASP .NET将所选文件转换为wav格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要开发一个使用文件上传器选择多个音频文件的Web应用程序,当我点击上传按钮时,音频文件应该转换为.wav格式,并且应该保存在应用程序文件夹中。我可以这样做吗。
以下是我在aspx页面中的代码
< h4 > 选择要上传的文件:< / h4 >
< asp:FileUpload ID = FileUpload1 AllowMultiple = true
runat = server > < / asp:FileUpload >
< br < span class =code-attribute> / >
< br / >
< ; asp:按钮 ID = UploadBtn
文字 = 上传文件
OnClick = UploadBtn_Click
runat = 服务器 > < / asp:按钮 >
< hr / >
< asp:标签 ID = UploadStatusLabel
< span class =code-attribute> runat = server >
< < span class =code-leadattribute> / asp:Label >
以下是我在.cs页面的代码
protected void UploadBtn_Click( object sender,EventArgs e)
{
< span class =code-comment> // 指定服务器上的路径
// 将上传的文件保存到。
string savePath = @ c:\ temp \ uploads;
// 在尝试保存文件之前,请确认
// FileUpload控件包含文件。
if (FileUpload1.HasFile)
{
// 获取名称要上传的文件。
string fileName = Server.HtmlEncode(FileUpload1.FileName);
// 获取上传文件的扩展名。
string extension = System.IO.Path.GetExtension(fileName);
// 仅允许带有.ds2或.dss扩展名的文件
// 上传。
if ((extension == 。ds2)||(extension == < span class =code-string> 。ds2)||(extension == 。m4a))
{
// 附加要上传到路径的文件的名称。
savePath + = fileName;
// 调用SaveAs方法保存
< span class =code-comment> // 将文件上传到指定路径。
// 此示例不执行所有
// 必要的错误检查。
// 如果文件包含同名
// 已存在于指定路径中,
// 上传的文件会覆盖它。
FileUpload1.SaveAs(savePath);
// 通知用户他们的文件已成功上传。
UploadStatusLabel.Text = 您的文件已成功上传。;
}
其他
{
// < span class =code-comment>通知用户他们的文件未上传的原因。
UploadStatusLabel.Text = 您的文件未上传,因为 +
它没有有.ds2或.dss扩展名。;
}
}
}
什么我试过了:
以上是我的代码如何添加转换.dss,.ds2和m4a文件的功能并保存在应用程序文件夹中我点击上传按钮
解决方案
尝试这些线程
在优化后播放音频,但音频不会在Chrome浏览器中播放 [ ^ ]
如何以编程方式转换dss和ds2文件并在所有浏览器中播放转换后的文件 [ ^ ]
如何消除domexception:元素没有支持的源。 [ ^ ]
I need to develop a web application which selects multiple audio files using file uploader and when i click on upload button the audio files should get converted to .wav format and should get saved in the application folder.how can i do this.
Below is my code in aspx page page
<h4>Select a file to upload:</h4>
<asp:FileUpload ID="FileUpload1" AllowMultiple="true"
runat="server"></asp:FileUpload>
<br />
<br />
<asp:Button ID="UploadBtn"
Text="Upload file"
OnClick="UploadBtn_Click"
runat="server"></asp:Button>
<hr />
<asp:Label ID="UploadStatusLabel"
runat="server">
</asp:Label>
Below is my code in .cs page
protected void UploadBtn_Click(object sender, EventArgs e)
{
// Specify the path on the server to
// save the uploaded file to.
string savePath = @"c:\temp\uploads";
// Before attempting to save the file, verify
// that the FileUpload control contains a file.
if (FileUpload1.HasFile)
{
// Get the name of the file to upload.
string fileName = Server.HtmlEncode(FileUpload1.FileName);
// Get the extension of the uploaded file.
string extension = System.IO.Path.GetExtension(fileName);
// Allow only files with .ds2 or .dss extensions
// to be uploaded.
if ((extension == ".ds2") || (extension == ".ds2") || (extension == ".m4a"))
{
// Append the name of the file to upload to the path.
savePath += fileName;
// Call the SaveAs method to save the
// uploaded file to the specified path.
// This example does not perform all
// the necessary error checking.
// If a file with the same name
// already exists in the specified path,
// the uploaded file overwrites it.
FileUpload1.SaveAs(savePath);
// Notify the user that their file was successfully uploaded.
UploadStatusLabel.Text = "Your file was uploaded successfully.";
}
else
{
// Notify the user why their file was not uploaded.
UploadStatusLabel.Text = "Your file was not uploaded because " +
"it does not have a .ds2 or .dss extension.";
}
}
}
What I have tried:
Above is my code how can i add the functionality to convert .dss,.ds2 and m4a files and save in application folder when i click on upload button
解决方案
Try these threads
Displays audio after exceution but audio doesnot gets played in chrome browser[^]
How to convert dss and ds2 files programatically and play those converted files in all the browsers[^]
How to eliminate domexception: the element has no supported sources.[^]
这篇关于如何使用ASP .NET将所选文件转换为wav格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文