求救,这个怎么获取文件名??

我说我行就是行 2011-06-29 10:38:12
我这个是上传视频的一个代码!期间,我要判断视频格式,如果是avi的可以通过,否则,弹出一个警告,只能上传avi的
前台代码
  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
width="550" height="100" id="fileUpload" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="fileUpload.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent">
<PARAM NAME=FlashVars VALUE='uploadPage=Upload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()'>
<embed src="fileUpload.swf"
FlashVars='uploadPage=Upload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()'
quality="high" wmode="transparent" width="550" height="100"
name="fileUpload" align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton>

后台:

protected void Page_Load(object sender, EventArgs e)
{


string jscript = "function UploadComplete(){";
jscript += string.Format("__doPostBack('{0}','');", LinkButton1.ClientID.Replace("_", "$"));

jscript += "};";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "FileCompleteUpload", jscript, true);
}
protected string GetFlashVars()
{

return "?" + Server.UrlEncode(Request.QueryString.ToString());
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//这里面不知道怎么写,就是获取上传的文件名或者在这里面判断,如果获取cc.rmvb的话,
//我就可以这样写了
string avi = "cc.rmvb";

string c = avi.Substring(avi.LastIndexOf("."));
if(c!=".avi")
{
弹出警告
}else
{
弹出上传成功
}


现在的问题,就是怎么获取???请各位大侠帮个忙撒!


}



UpLoad.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public class Upload : IHttpHandler
{
public Upload()
{
}

#region IHttpHandler Members

public bool IsReusable
{
get { return true; }
}

public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
string tempFile = context.Request.PhysicalApplicationPath;
for (int j = 0; j < context.Request.Files.Count; j++)
{
HttpPostedFile uploadFile = context.Request.Files[j];
string avi = uploadFile.FileName;

string c = avi.Substring(avi.LastIndexOf("."));
if (c!= ".avi")
{
//在这里面写了,可不弹出这句话,但这句话进入了
HttpContext.Current.Response.Write("<Script>alert('上传视频格式只能是avi!');</Script>");
// return;
}
else
{
if (uploadFile.ContentLength > 0)
{
uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "images/video\\", uploadFile.FileName));
}
}
}
}

HttpContext.Current.Response.Write(" ");
}

#endregion
}


...全文
111 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
没人会吗??我就是想在LinkBtton当中获取上传的文件名!怎么获取???
小阳 2011-06-29
  • 打赏
  • 举报
回复
接分!
IT0329 2011-06-29
  • 打赏
  • 举报
回复
这个给他一个字段,然后通过字段来接受这个url地址,然后前台输出下不就可以获取到了么?我就这么干的!
老毕 2011-06-29
  • 打赏
  • 举报
回复
我可耻地伸手了……
isjoe 2011-06-29
  • 打赏
  • 举报
回复
接分。。。。。。。
  • 打赏
  • 举报
回复
搞定!
完整版上传代码!
前台一样,后台

protected void Page_Load(object sender, EventArgs e)
{


string jscript = "function UploadComplete(){";
jscript += string.Format("__doPostBack('{0}','');", LinkButton1.ClientID.Replace("_", "$"));

jscript += "};";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "FileCompleteUpload", jscript, true);
}
protected string GetFlashVars()
{

return "?" + Server.UrlEncode(Request.QueryString.ToString());
}
protected void LinkButton1_Click(object sender, EventArgs e)
{

string filename = Upload.msgs;
string format = filename.Substring(filename.LastIndexOf("."));
if (format != ".flv")
{
this.lblMes.Text = "只支持flv格式的视频!";
// Response.Write("<script>alert('只支持flv格式的视频!');</script>");
}
else
{
this.lblMes.Text = "上传成功!";
//Response.Write("<script>alert('上传成功!');</script>");
}
}

UpLoad.cs类

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public class Upload : IHttpHandler
{
public Upload()
{
}

#region IHttpHandler Members

public bool IsReusable
{
get { return true; }
}
public static string msgs = string.Empty;
public void ProcessRequest(HttpContext context)
{
string c = string.Empty;
HttpPostedFile uploadFile = null;
string filename=null;
string tempFile = null;
if (context.Request.Files.Count > 0)
{
tempFile = context.Request.PhysicalApplicationPath;
for (int j = 0; j < context.Request.Files.Count; j++)
{
uploadFile = context.Request.Files[j];
filename= uploadFile.FileName;


c = filename.Substring(filename.LastIndexOf("."));

}
}
string str = string.Empty;
msgs = filename;
if (c != ".flv")
{
return;
}
else
{
if (uploadFile.ContentLength > 0)
{
uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "images/video\\", uploadFile.FileName));

}
}
HttpContext.Current.Response.Write(" ");
}

#endregion
}


欢迎接分!

17,741

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧