Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<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";
}
}
}
Posted

1 solution

XML
<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(event)
{
  if(event.button==2)
   {
     alert(status);
     return false;
   }
}
</script>
 
Share this answer
 
Comments
Member 11026295 26-Aug-14 3:23am    
Where this code is to be place
Ankit_Vaghela 26-Aug-14 5:07am    
In your html page head section.
Member 11026295 26-Aug-14 6:17am    
I want uploaded pdf file should be rightclick disabled

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900