try
{
string sql = "";
if (isVS == "tb_Sound") //判断教程是否是语音类型
{
//判断用户上传的文件类型
if (FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1) == "mp3")
{
//判断用户上传的语音教程是否存在
if (!File.Exists(Server.MapPath(".") + "\\Sound\\" + this.FileUpload1.FileName))
{
sql = "insert into tb_Sound(SoundType,SoundName,SoundUrl,ClickSum,SoundContent,Name) values('" + typ + "','" + vsname + "','" + this.FileUpload1.FileName + "','" + clicksum + "','" + content + "','" + name + "')";
//设置路径用于保存上传的语音
Path = Server.MapPath("./") + "Sound" + "\\" + this.FileUpload1.FileName;
if (mydo.adlData(sql))
{
//将文件保存到指定位置
FileUpload1.PostedFile.SaveAs(Path);
Page.RegisterStartupScript("true", "<script>alert('上传成功!')</script>");
txtName.Text="";
txtContent.Text="";
}
else
{
Page.RegisterStartupScript("true", "<script>alert('上传失败!')</script>");
}
}
else
Page.RegisterStartupScript("false", "<script>alert('教程名称已经存在!')</script>");
}
else
RegisterStartupScript("false", "<script>alert('只能上传mp3类型!')</script>");
}
else
{
//判断用户上传的文件类型
string type = FileUpload1.PostedFile.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1);
if (type == "rmvb"||type == "wmv" )
{
//判断用户上传的视频教程是否存在
if (!File.Exists(Server.MapPath(".") + "\\Video\\" + this.FileUpload1.FileName))
{
sql = "insert into tb_Video(VideoType,VideoName,VideoUrl,ClickSum,VideoContent,Name) values(" + typ + ",'" + vsname + "','" + this.FileUpload1.FileName + "'," + clicksum + ",'" + content + "','" + name + "')";
Path = Server.MapPath("~/") + "Video" + "\\" + this.FileUpload1.FileName;
if (mydo.adlData(sql))
{
FileUpload1.PostedFile.SaveAs(Path);
Page.RegisterStartupScript("true", "<script>alert('上传成功!')</script>");
txtName.Text="";
txtContent.Text="";
}
else
{
Page.RegisterStartupScript("true", "<script>alert('上传失败!')</script>");
}
}
else
{
Page.RegisterStartupScript("false", "<script>alert('教程名称已经存在!')</script>");
}
}
else
RegisterStartupScript("false", "<script>alert('只能上传wmv类型!')</script>");
}
}
catch (Exception ex)
{
Page.RegisterStartupScript("false", "<script>alert('上传教程不能为空!')</script>");
}
}
为什么mp3格式的文件能上传,而视频却不能上传
{
string sql = "";
if (isVS == "tb_Sound") //判断教程是否是语音类型
{
//判断用户上传的文件类型
if (FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1) == "mp3")
{
//判断用户上传的语音教程是否存在
if (!File.Exists(Server.MapPath(".") + "\\Sound\\" + this.FileUpload1.FileName))
{
sql = "insert into tb_Sound(SoundType,SoundName,SoundUrl,ClickSum,SoundContent,Name) values('" + typ + "','" + vsname + "','" + this.FileUpload1.FileName + "','" + clicksum + "','" + content + "','" + name + "')";
//设置路径用于保存上传的语音
Path = Server.MapPath("./") + "Sound" + "\\" + this.FileUpload1.FileName;
if (mydo.adlData(sql))
{
//将文件保存到指定位置
FileUpload1.PostedFile.SaveAs(Path);
Page.RegisterStartupScript("true", "<script>alert('上传成功!')</script>");
txtName.Text="";
txtContent.Text="";
}
else
{
Page.RegisterStartupScript("true", "<script>alert('上传失败!')</script>");
}
}
else
Page.RegisterStartupScript("false", "<script>alert('教程名称已经存在!')</script>");
}
else
RegisterStartupScript("false", "<script>alert('只能上传mp3类型!')</script>");
}
else
{
//判断用户上传的文件类型
string type = FileUpload1.PostedFile.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1);
if (type == "rmvb"||type == "wmv" )
{
//判断用户上传的视频教程是否存在
if (!File.Exists(Server.MapPath(".") + "\\Video\\" + this.FileUpload1.FileName))
{
sql = "insert into tb_Video(VideoType,VideoName,VideoUrl,ClickSum,VideoContent,Name) values(" + typ + ",'" + vsname + "','" + this.FileUpload1.FileName + "'," + clicksum + ",'" + content + "','" + name + "')";
Path = Server.MapPath("~/") + "Video" + "\\" + this.FileUpload1.FileName;
if (mydo.adlData(sql))
{
FileUpload1.PostedFile.SaveAs(Path);
Page.RegisterStartupScript("true", "<script>alert('上传成功!')</script>");
txtName.Text="";
txtContent.Text="";
}
else
{
Page.RegisterStartupScript("true", "<script>alert('上传失败!')</script>");
}
}
else
{
Page.RegisterStartupScript("false", "<script>alert('教程名称已经存在!')</script>");
}
}
else
RegisterStartupScript("false", "<script>alert('只能上传wmv类型!')</script>");
}
}
catch (Exception ex)
{
Page.RegisterStartupScript("false", "<script>alert('上传教程不能为空!')</script>");
}
}
为什么mp3格式的文件能上传,而视频却不能上传
解决方案 »
- 菜鸟问题,绝对是给分题
- .net自带的 压缩问题
- 请问关于RequestType的问题.
- DevExpress中的XtraGrid如何去掉分组面板呀,不让用户进行分组操作
- winform中 想打印 datagirdview 的内容 怎么实现呀 先谢谢了 ...
- DataTable如何byVal赋值(深copy)
- WPF中如果不用Control.Focus()还可以用什么方法来设置焦点
- .WPF中CoverFlow控件UI刷新问题,很诡异!求解决!!!!在线等
- c# 开发的Web 页面如何设置默认打印为横向打印!
- C#正则表达问题[高手请进!!]
- 在windows里,一个端口能被多个程序监听嘛?
- 一个tooltrip工具栏的问题。
string type = FileUpload1.PostedFile.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1);
if (type == "rmvb"||type == "wmv" ) 你的是这些格式吗?