111,098
社区成员




[AjaxMethod]
public void Add()
{
string Vid; string Vcatalogue; string Filename; string Vname=""; string Vtype = ""; int Vsize; string Vuptime; string Vurl; string Vupremark = "qwety"; int Vnumber;
Vid = System.Guid.NewGuid().ToString();
Vcatalogue = this.txtvcatalogue.Text.Trim();
Vnumber = int.Parse(this.txtvnumber.Text.Trim());
string pic = "";
#region 视频上传
try
{
HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];//获得用户提交的文件
Filename = postedFile.FileName;
string suffixstr = Filename.Substring(Filename.LastIndexOf('.') + 1);//获取文件后缀
if (suffixstr == "avi" || suffixstr == "mp4" || suffixstr == "rmvb")//判断文件类型是不是avi、mp4、rmvb
{
Vsize=FileUploadField1.PostedFile.ContentLength;
if (Vsize < 104857600)
{
#region 根据文件名分别获取获取文件名和后缀
switch (suffixstr) {
case "avi": Vname = Filename.Substring(0, Filename.Length - 4);
Vtype = "avi";
break;
case "mp4": Vname = Filename.Substring(0, Filename.Length - 4);
Vtype = "mp4";
break;
case "rmvb": Vname = Filename.Substring(0, Filename.Length - 5);
Vtype = "rmvb";
break;
}
#endregion
string savePath;
string dir = HttpContext.Current.Request.PhysicalApplicationPath;//当前应用程序的根目录
savePath = "~\\Admin\\upload\\video\\" + Vcatalogue + "\\";//保存文件的目录
string _savepath = Server.MapPath(savePath);
if (System.IO.Directory.Exists(_savepath) == false)//如果不存在就创建file文件夹
{
System.IO.Directory.CreateDirectory(_savepath);
}
//string date = DateTime.Now.ToString("yyyy-M-d") + "-" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString() + "-";//根据自己需要添加
pic = "Admin\\upload\\video\\"+Vcatalogue+"\\" + Filename;
if (File.Exists(savePath))
{
File.Delete(savePath);//如果文件已经存在就将已存在的文件删除
}
FileUploadField1.PostedFile.SaveAs(_savepath+ System.IO.Path.GetFileName(Filename));
Vurl = pic;
Vuptime = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
int i=VI.Add(Vid, Vcatalogue, Vname, Vtype, Vsize, Vuptime, Vurl, Vupremark, Vnumber);
if (i > 0)
{
Ext.Msg.Show(new MessageBox.Config
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.INFO,
Title = "Fail",
Message = "上传成功!"
});
}
else {
Ext.Msg.Show(new MessageBox.Config
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.ERROR,
Title = "Fail",
Message = "保存失败!"
});
}
}
else {
Ext.Msg.Show(new MessageBox.Config
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.ERROR,
Title = "Fail",
Message = "请选择100M以内的视频文件!"
});
}
}
else
{
Ext.Msg.Show(new MessageBox.Config
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.ERROR,
Title = "Fail",
Message = "请选择mp4、avi或rmvb文件!"
});
}
//Vid, Vcatalogue, Vname, Vtype, Vsize, Vuptime, Vurl, Vupremark ,Vnumber
}