如何禁用右键单击上传的pdf文件 [英] how to disable right click on uploaded pdf file

查看:98
本文介绍了如何禁用右键单击上传的pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre lang =c#>< pre lang =c#> 



protected void Upload_btn_Click(object sender ,EventArgs e)

{

String fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);

Panel_Sucess.Visible = false;

if(FileUpload1.HasFile)

{



if(File.Exists(D:\\\ \\ WebSite examples \\myproject \\QuestionBank \\+ fileName))

{

Panel_error.Visible = true;

label_error.Text =服务器上已存在名称为+ fileName +的文件。;

返回;

}



int fileSize = FileUpload1.PostedFile.ContentLength;

if(fileSize> 2 * 1024 * 1024)

{

Panel_error.Visible = true;

label_error.Text =图像的文件大小太大。允许的最大文件大小为1 MB;

返回;

}

string fileExtension = Path.GetExtension(fileName);

fileExtension = fileExtension.ToLower();

string [] acceptedFileTypes = new string [1];

acceptedFileTypes [0] =。pdf;



bool acceptFile = false;

for(int i = 0; i< 1; i ++)

{

if(fileExtension == acceptedFileTypes [i])

{

acceptFile = true;

}

}

if(!acceptFile)

{

Panel_error.Visible = true;

label_error.Text =您尝试上传的文件不是允许的文件类型,文件应该是 .pdf ;

return;

}

Panel_error.Visible = false;

var path =D:\\Website examples \\myproject \\ QuestionBank \\;

var directoryinfo = new DirectoryInfo(path);

string s1 =(String)Session [t1];

SqlConnection con = new SqlConnection(Data Source = USER-PC; Initial Catalog = myproject; User ID = sa; Password = Password1);

SqlCommand cmd = new SqlCommand(Select College来自Registration_table,其中College ='+ s1 +',con);

if(directoryinfo.Exists)

{



if(!Directory.Exists(path + s1))

{

var newfolder = directoryinfo.CreateSubdirectory(+ s1);

FileUpload1.SaveAs(Server.MapPath(〜/+ newfolder +\\)+ fileName);





Response.Write(< script language ='javascript'> window.alert('QuestionBank Successfully Uploaded');< / script>);



}



else

Panel_error.Visible = true;

label_error.Text =一个学院只能上传一个Qbank;

}

}

}

解决方案

 <   script     language   =  javascript >  
document.onmousedown = disableclick;
status =右键单击已禁用;
函数disableclick(event)
{
if(event.button == 2)
{
alert(status);
返回false;
}
}
< / script >


<pre lang="c#"><pre lang="c#">


protected void Upload_btn_Click(object sender, EventArgs e)
{
String fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
Panel_Sucess.Visible = false;
if (FileUpload1.HasFile)
{

if (File.Exists("D:\\WebSite examples\\myproject\\QuestionBank\\" + fileName))
{
Panel_error.Visible = true;
label_error.Text = "A file with the name " + fileName + " already exists on the server.";
return;
}

int fileSize = FileUpload1.PostedFile.ContentLength;
if (fileSize > 2*1024 * 1024)
{
Panel_error.Visible = true;
label_error.Text = "Filesize of image is too large. Maximum file size permitted is 1 MB";
return;
}
string fileExtension = Path.GetExtension(fileName);
fileExtension = fileExtension.ToLower();
string[] acceptedFileTypes = new string[1];
acceptedFileTypes[0] = ".pdf";

bool acceptFile = false;
for (int i = 0; i <1; i++)
{
if (fileExtension == acceptedFileTypes[i])
{
acceptFile = true;
}
}
if (!acceptFile)
{
Panel_error.Visible = true;
label_error.Text = "The file you are trying to upload is not a permitted file type,file should be .pdf ;
return;
}
Panel_error.Visible = false;
var path = "D:\\Website examples\\myproject\\QuestionBank\\";
var directoryinfo = new DirectoryInfo(path);
string s1 = (String)Session["t1"];
SqlConnection con = new SqlConnection("Data Source=USER-PC;Initial Catalog=myproject;User ID=sa;Password=Password1");
SqlCommand cmd = new SqlCommand("Select College from Registration_table where College='" + s1 + "'", con);
if (directoryinfo.Exists)
{

if (!Directory.Exists(path + s1))
{
var newfolder = directoryinfo.CreateSubdirectory("" + s1);
FileUpload1.SaveAs(Server.MapPath("~/" + newfolder + "\\") +fileName);


Response.Write("<script language='javascript'>window.alert('QuestionBank Successfully Uploaded');</script>");

}

else
Panel_error.Visible = true;
label_error.Text = "one College can upload only one Qbank";
}
}
}

解决方案

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(event)
{
  if(event.button==2)
   {
     alert(status);
     return false;
   }
}
</script>


这篇关于如何禁用右键单击上传的pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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