c#upload任何扩展名的下载视频文件 [英] c# upload download video file of any extension

查看:80
本文介绍了c#upload任何扩展名的下载视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从任何扩展程序的管理员端上传软件,并通过提供普通用户单独的用户ID和密码来下载软件,从管理员端只访问普通用户。任何想法请帮助。



用于上传我已使用此

 字符串 filename = Path.GetFileName(fileUpload1.PostedFile.FileName ); 
fileUpload1.SaveAs(Server.MapPath( Files / + filename));
conn.Open();
SqlCommand cmd = new SqlCommand( insert into upload(FileName,FilePath)值(@ Name,@ Path),conn);
cmd.Parameters.AddWithValue( @ Name,filename);
cmd.Parameters.AddWithValue( @ Path Files / + filename);
cmd.ExecuteNonQuery();
conn.Close();
BindGridviewData();
< / pre >



下载使用此

 LinkBut​​ton lnkbtn = sender  as  LinkBut​​ton; 
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
string filePath = gvDetails.DataKeys [gvrow.RowIndex] .Value.ToString();
Response.ContentType = ;
Response.AddHeader( Content-Disposition attachment; filename = \ + filePath + \ );
Response.TransmitFile(Server.MapPath(filePath));
Response.End();
< / pre >



但它不支持视频文件,你是否知道如何从管理员用户下载软件的普通用户访问权限。通过定义角色可以解决问题

解决方案

如果要启用用户下载任何文件类型,可以使用application / octet-stream作为ContentType

< pre lang =c#> Response.ContentType = application / octet-stream;


I want to make upload of software from admin side of any extension and give access to only normal user from admin side by providing normal user separate userid and password for downloading the software.Any idea please help.

for upload i have used this

string filename = Path.GetFileName(fileUpload1.PostedFile.FileName);
fileUpload1.SaveAs(Server.MapPath("Files/"+filename));
conn.Open();
SqlCommand cmd = new SqlCommand("insert into upload(FileName,FilePath) values(@Name,@Path)",conn);
cmd.Parameters.AddWithValue("@Name",filename );
cmd.Parameters.AddWithValue("@Path", "Files/"+filename );
cmd.ExecuteNonQuery();
conn.Close();
BindGridviewData();
</pre>


for download used this

LinkButton lnkbtn = sender as LinkButton;
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
string filePath = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
Response.ContentType = "";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
Response.TransmitFile(Server.MapPath(filePath));
Response.End();
</pre>


but it is not supporting video file and do you have idea whether how to give access for normal user from admin user to download software.By defining Roles may it solve the problem

解决方案

If you want to enable user downloading any file type, you can use application/octet-stream as your ContentType

Response.ContentType = "application/octet-stream";


这篇关于c#upload任何扩展名的下载视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆