示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                if (FileUploadControl.HasFile)
                {
                    try
                    {
                        string filename = Path.GetFileName(FileUploadControl.FileName);
                        FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
                        StatusLabel.Text = "Upload status: File uploaded!";
                        string       toRead = Server.MapPath(FileUploadControl.FileName);
                        StreamReader reader = File.OpenText(toRead);
                        string       line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            StaticSession.ws.receiveMessage(line);
                        }
                        reader.Close();
                    }
                    catch (Exception ex)
                    {
                        StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                    }
                }
            }
            GenerateDot gen = new GenerateDot();
            String      s   = StaticSession.ws.graphAvlTree();

            gen.createDot(s, "avlTree");
            s = StaticSession.ws.sendArbolB();
            gen.createDot(s, "btree");
            s = StaticSession.ws.sendHashGraph();
            gen.createDot(s, "hashTable");
        }
示例#2
0
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                try
                {
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(Server.MapPath("~/") + filename); // Save a file in server.

                    oExcel    ox = new oExcel(Server.MapPath("~/") + filename);
                    DataTable dt = ox.GetDataSQL("Select * from [Sheet1$]");
                    oUsers    ou = new oUsers();

                    foreach (DataRow dr in dt.Rows)
                    {
                        ou.CreateUser(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString()); // 0: UserCode, 1: Password, 2: Roll Name, 3: Email
                    }
                    StatusLabel.Text = "Import status: File had imported.";
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Import status: The file could not be imported. The following error occured: " + ex.Message;
                }
            }
        }
    protected void UploadButton_Click(object sender, EventArgs e)
    {
        var CaseId = Request.QueryString["CaseId"];

        if (FileUploadControl.HasFile)
        {
            try
            {
                string filename = Path.GetFileName(FileUploadControl.FileName);
                FileUploadControl.SaveAs(Server.MapPath("~/CrimeImages/") + filename);

                using (OdbcConnection connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    connection.Open();

                    string      query   = "insert into crimeimage values (null,'" + CaseId + "','" + filename + "')";
                    OdbcCommand command = new OdbcCommand(query, connection);
                    command.ExecuteNonQuery();

                    connection.Close();
                }

                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "success();", true);
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "error();", true);
            }
        }
    }
示例#4
0
 // The upload picture buttonw as pressed
 protected void UploadButton_Click(object sender, EventArgs e)
 {
     using (SliceOfPieClient.Service.SliceOfPieServiceClient serv = new SliceOfPieClient.Service.SliceOfPieServiceClient())
     {
         //First it check if a file was selected
         if (FileUploadControl.HasFile)
         {
             // gets the file name
             string ImgName = System.IO.Path.GetFileName(FileUploadControl.FileName);
             // It saves the picture on the filesystem
             string ThisImg = Server.MapPath("~/images/" + ImgName);
             FileUploadControl.SaveAs(ThisImg);
             // It creates a new bitmap, and then a new object of our own Picture class
             Bitmap  bm  = new Bitmap(ThisImg);
             Picture pic = new Picture(bm);
             // Finally adds the image to the documents imagelist
             if (activeDoc != null)
             {
                 activeDoc.Images.Add(pic);
             }
         }
         // It also saves the document to the server, after the picture is added
         serv.SaveDocumentOnServer(activeProject, activeDoc, WelcomeForm.active);
         // Updates the panel in which you can see which pictures are added, so you can see it as soon as you click upload
         UpdateImagePanel();
         ImagesCurrentlyBox.Visible = true;
         ImageBox.Visible           = true;
     }
 }
示例#5
0
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(ViewState["ID"]);

            if (FileUploadControl.HasFile)
            {
                try
                {
                    string originalFilename = Path.GetFileName(FileUploadControl.FileName);
                    string extension        = Path.GetExtension(FileUploadControl.FileName);
                    string filename         = Guid.NewGuid().ToString();

                    FileUploadControl.SaveAs(Server.MapPath("~/Forwarding/Transaction/EstimateFiles/") + filename + "." + extension);
                    hdnFileName.Value = filename;

                    //Update file name in database
                    JobBLL.SaveEstimateFile(id, filename, originalFilename);

                    ClientScript.RegisterStartupScript(typeof(Page), "SymbolError", "<script type='text/javascript'>sendValue();</script>");
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
示例#6
0
    public string FileUpload()
    {
        string str = string.Empty;

        if (FileUploadControl.HasFile)
        {
            try
            {
                if (FileUploadControl.PostedFile.ContentType == "image/png")
                {
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(Server.MapPath("~/images/") + filename);
                    StatusLabel.Text = "Upload status: File uploaded!";
                    str = Server.MapPath("~/images/") + filename;
                }
                else
                {
                    StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
                }
            }
            catch (Exception ex)
            {
                StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
        return(str);
    }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                try
                {
                    Session["FileName"] = FileUploadControl.FileName;
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(Server.MapPath("~/Resources/Import/") + filename);

                    //Decimate Mesh
                    funcDecimateMesh();

                    //Display Decimation information to client
                    UpdateClientInformation();


                    //Update AssetBundle
                    funcGenerateAssetBundle();
                }
                catch (Exception ex)
                {
                    labResultNotification.Text = "We apologize for the inconvenience it seems either the file is Corrupted or unsupported file format.";
                }
            }
        }
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                try
                {
                    string filePath = ConfigurationManager.AppSettings["LocalFilePath"];
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(filePath + filename);

                    ProcessFile();

                    StatusLabel.Text      = "Upload status: File uploaded !";
                    StatusLabel.ForeColor = System.Drawing.Color.Green;
                }
                catch (Exception ex)
                {
                    StatusLabel.Text      = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                    StatusLabel.ForeColor = System.Drawing.Color.Red;
                }
            }
            else
            {
                StatusLabel.Text      = "You must select a file";
                StatusLabel.ForeColor = System.Drawing.Color.Red;
            }
        }
示例#9
0
        private bool EsImagenCargada()
        {
            bool resultado = false;

            if (FileUploadControl.HasFile)
            {
                try
                {
                    if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
                    {
                        string filename = Path.GetFileName(FileUploadControl.FileName);
                        FileUploadControl.SaveAs(Server.MapPath("~/images/") + filename);
                        hdnRutaImagen.Value = "../images/" + filename;
                        resultado           = true;
                    }
                    else
                    {
                        messageBox.ShowMessage("Solo puede cargar imagenes .JPG");
                    }
                }
                catch (Exception ex)
                {
                    hdnRutaImagen.Value = "";
                    messageBox.ShowMessage(ex.Message + ex.StackTrace);
                }
            }
            else
            {
                messageBox.ShowMessage("Debe agregar un logo a la empresa");
            }
            return(resultado);
        }
示例#10
0
        protected void Button5_Click(object sender, EventArgs e)
        {
            string str;

            if (FileUploadControl.HasFile)
            {
                try
                {
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    str = Server.MapPath("~/jegadesh/") + filename;
                    FileUploadControl.SaveAs(Server.MapPath("~/jegadesh/") + filename);
                    StreamReader reader1 = new StreamReader(str);
                    string       text1   = reader1.ReadToEnd();
                    TextBox1.Text = text1;
                    reader1.Close();
                    // Label2.Text = "Upload status: File uploaded!";
                    FileInfo fi      = new FileInfo(str);
                    double   imageMB = fi.Length;
                    Session["filesi"] = imageMB;
                    //Label13.Text = "File Name: " + fi.Name;
                    //Label14.Text = "Text Size: " + imageMB + " Bytes";
                    //Session["filesize"] = Label14.Text;
                }


                catch (Exception ex)
                {
                    Label2.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
示例#11
0
        protected void Button1_Click1(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                try
                {
                    filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(Server.MapPath("~/") + filename);

                    // string texto = File.ReadAllText(Server.MapPath("~/") + filename);
                    string[] lineas = File.ReadAllLines(Server.MapPath("~/") + filename);

                    int i = 0;


                    while (lineas.Length > i)
                    {
                        TextBox1.Text = TextBox1.Text + lineas[i] + "\r\n";
                        //TextBox1.Text = texto + Environment.NewLine;
                        i++;
                    }


                    //TextBox1.Text = texto + Environment.NewLine;
                }
                catch (Exception ex)
                {
                    TextBox1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
示例#12
0
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            string[] tableNames = new string[] { "GUID", "Date", "Double", "Int", "String" };
            string   PrimaryKey = "GUID";
            string   tableName  = "[ExampleTable]";

            if (FileUploadControl.HasFile)
            {
                try
                {
                    if (FileUploadControl.PostedFile.ContentLength < 302400 && FileUploadControl.PostedFile.ContentType == "application/vnd.ms-excel")
                    {
                        string filename = FileUploadControl.FileName;
                        FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
                        StatusLabel.Text = "Upload status: File uploaded,Validating...";
                        ProcessFile processResult = new ProcessFile(Server.MapPath("~/ ") + filename, tableNames, tableName, PrimaryKey);
                        StatusLabel.Text = processResult.Process();
                        GridView1.DataBind();
                    }
                    else
                    {
                        StatusLabel.Text = "Upload status: The file must be a csv and less than 300 kb";
                    }
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
示例#13
0
 protected void UploadButton_Click(object sender, EventArgs e)
 {
     if (FileUploadControl.HasFile)
     {
         try
         {
             if ((FileUploadControl.PostedFile.ContentType == "image/jpeg") ||
                 (FileUploadControl.PostedFile.ContentType == "image/pjpeg") ||
                 (FileUploadControl.PostedFile.ContentType == "image/png") ||
                 (FileUploadControl.PostedFile.ContentType == "image/gif"))
             {
                 if (FileUploadControl.PostedFile.ContentLength < 10485760)
                 {
                     string filename = Path.GetFileName(FileUploadControl.FileName);
                     FileUploadControl.SaveAs(Server.MapPath("~/Images/") + filename);
                     databaseHelper.addProduct(txtProdName.Text, txtProdPrice.Text, txtProdIng.Text, txtProdDesc.Text, filename);
                     StatusLabel.Text = "Upload status: Product Added!";
                 }
                 else
                 {
                     StatusLabel.Text = "Upload status: The file has to be less than 10 mb!";
                 }
             }
             else
             {
                 StatusLabel.Text = "Upload status: Only JPEG, GIF, and PNG files are accepted!";
             }
         }
         catch (Exception ex)
         {
             StatusLabel.Text = "Upload status: The product could not be added. The following error occured: " + ex.Message;
         }
     }
 }
        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                string filename = "";
                if (FileUploadControl.HasFile)
                {
                    if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
                    {
                        filename = Path.GetFileName(FileUploadControl.FileName);
                        FileUploadControl.SaveAs(Server.MapPath("~/MemberProfilePicture/" + filename));
                        imgProfileImage.ImageUrl = "~/" + Server.MapPath("~/MemberProfilePicture/" + filename);
                    }
                    else
                    {
                        StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
                    }
                }

                UpdateUser();
                ClearValues();
                txtSearch.Text = "";
                txtSearch.Focus();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#15
0
    protected void btnupload_Click(object sender, EventArgs e)
    {
        // Image1.Visible = true;

        //Session["FilePath"] = FileUploadControl.FileName;
        string fPath = ConfigurationManager.AppSettings["EXCEL_SHEET"];

        EmailSender.DAO_Message objMessage = new EmailSender.DAO_Message();

        if (FileUploadControl.HasFile)
        {
            if (FileUploadControl.PostedFile.ContentLength < 10240000)
            {
                string fname = "";
                fname = FileUploadControl.PostedFile.FileName;
                string file = "";
                file = FileUploadControl.FileName;
                string filename = "";
                filename = getFileName("Support") + file.Substring(file.IndexOf("."), (file.Length - file.IndexOf(".")));

                txtupload.Text = fPath + "/" + filename;
                FileUploadControl.SaveAs(fPath + "/" + filename);
                // FileUploadControl.SaveAs(fPath);

                lblFileName.Text = FileUploadControl.FileName;
            }
        }
        else
        {
            lblMsg.Text = "Please upload file of size less than 10MB";
        }
    }
示例#16
0
    private bool ManageUpload(out string error, out string fileName)
    {
        string fileExtension = Path.GetExtension(FileUploadControl.FileName).ToLower();

        string[] allowedExtensions = { ".png", ".jpeg", ".jpg" };
        if (!allowedExtensions.Contains(fileExtension))
        {
            error    = "File extension not allowed.";
            fileName = "";
            return(false);
        }

        string serverPath = Server.MapPath("uploads\\");

        fileName = FileUploadControl.FileName;

        string path  = Path.Combine(serverPath, fileName);
        int    index = 0;

        while (File.Exists(path))
        {
            ++index;
            fileName = Path.GetFileNameWithoutExtension(fileName) + " (" + index.ToString() + ")" + fileExtension;
            path     = Path.Combine(serverPath, fileName);
        }

        try {
            FileUploadControl.SaveAs(path);
        } catch (Exception ex) {
            error = ex.Message;
        }

        error = "File uploaded successfully!";
        return(true);
    }
示例#17
0
        protected void submitBtn_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                string filename;
                try
                {
                    filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(Server.MapPath("~/images/") + filename);
                }
                catch (Exception ex)
                {
                    return;
                }

                newsData _data = new newsData()
                {
                    Title = Title.Value.Replace(">", "").Replace("<", ""),
                    Image = "images/" + filename,
                    Text  = Content.Value.Replace(">", "").Replace("<", "")
                };

                DatabaseConnector.Inst.saveNewsData(Server.MapPath("~/ ") + "/json/updatableNews.json", _data, (string)Session["loggedIn"]);

                Response.Redirect("default.aspx");
            }
        }
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                if (!Directory.Exists(localDirectory))
                {
                    Directory.CreateDirectory(localDirectory);
                }
                try {
                    if (FileUploadControl.PostedFile.ContentType == "image/jpeg" || FileUploadControl.PostedFile.ContentType == "image/gif" || FileUploadControl.PostedFile.ContentType == "image/png")
                    {
                        string filename = Path.GetFileName(FileUploadControl.FileName);
                        FileUploadControl.SaveAs(localDirectory + @"\" + filename);
                        System.Drawing.Image image = FromFile(localDirectory + @"\" + filename);
                        int    width     = image.Width;
                        int    height    = image.Height;
                        double ratio     = ((double)(double)height / (double)width);
                        double newHeight = 500;
                        double newWidth  = newHeight / ratio;
                        System.Drawing.Image yourImage = resizeImage(image, new Size((int)newWidth, (int)newHeight));
                        yourImage.Save(localDirectory + "\\thumbs" + @"\" + filename);
                        yourImage.Dispose();
                        image.Dispose();

                        StatusLabel.Text = "Upload status: File uploaded!";
                    }
                    else
                    {
                        StatusLabel.Text = "Upload status: Only JPG, PNG, and GIF files are accepted!";
                    }
                } catch (Exception ex) {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
示例#19
0
 protected void UploadButton_Click(object sender, EventArgs e)
 {
     if (FileUploadControl.HasFile)
     {
         try
         {
             string filename = Path.GetFileName(FileUploadControl.FileName);
             FileUploadControl.SaveAs(Server.MapPath("~/folder/") + filename);
             using (SqlConnection conn = new SqlConnection(con))
             {
                 conn.Open();
                 SqlCommand comm = new SqlCommand();
                 comm.Connection  = conn;
                 comm.CommandType = CommandType.StoredProcedure;
                 comm.CommandText = "sp_uploadCv";
                 comm.Parameters.AddWithValue("@id", Request.QueryString["id"]);
                 comm.Parameters.AddWithValue("@link", MapPath("~/folder/") + filename);
                 int ire = comm.ExecuteNonQuery();
                 if (ire < 1)
                 {
                     Response.Write("<script>alert('Đăng thất bại')</script>");
                 }
                 else
                 {
                     Response.Write("<script>alert('Đăng thành công!!')</script>");
                 }
             }
             StatusLabel.Text = "Upload status: File uploaded!";
         }
         catch (Exception ex)
         {
             StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
         }
     }
 }
示例#20
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();

            var user = new User()
            {
                UserName = Username.Text
            };

            if (FileUploadControl.HasFile)
            {
                string fileName = user.UserName + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".jpg";
                FileUploadControl.SaveAs(Server.MapPath("~/Uploaded_Files/") + fileName);
                user.Avatar = fileName;
            }

            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
                Response.Redirect("~/");
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
 public void SaveFile(string filename)
 {
     if (FileUploadControl.HasFile)
     {
         FileUploadControl.SaveAs(Server.MapPath("~/Uploaded_Files") + filename);
     }
 }
示例#22
0
 protected void UploadButton_Click(object sender, System.EventArgs e)
 {
     if (FileUploadControl.HasFile)
     {
         try
         {
             if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
             {
                 if (FileUploadControl.PostedFile.ContentLength < 100002400)
                 {
                     string filename = Data.docid + ".jpg";
                     FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
                     StatusLabel.Text = "Upload status: File uploaded!";
                     this.Page_Load(null, null);
                 }
                 else
                 {
                     StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
                 }
             }
             else
             {
                 StatusLabel.Text = "Upload status: Only JPG files are accepted!";
             }
         }
         catch (Exception ex)
         {
             StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
         }
     }
 }
示例#23
0
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            divselect.Visible = false;

            if (FileUploadControl.HasFile)
            {
                if (                                                                                                                      //FileUploadControl.PostedFile.ContentType.Equals("application/vnd.ms-excel") ||  //formato 2003
                    FileUploadControl.PostedFile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) // formato superior 2003
                {
                    try
                    {
                        string[] name           = Path.GetFileName(FileUploadControl.FileName).ToString().Split('.');
                        string   UploadFilePath = Server.MapPath("UploadFile\\");
                        string   path           = UploadFilePath + name[0] + "_" + System.DateTime.Now.ToFileTime() + "." + name[1];

                        if (!Directory.Exists(UploadFilePath))
                        {
                            Directory.CreateDirectory(UploadFilePath);
                        }

                        FileUploadControl.SaveAs(path);
                        BasePage obj = new BasePage();
                        //Lê o Excel e converte para DataSet
                        DataTable dt = obj.ReadExcelFile(path);

                        bool ret = false;
                        if (Session["ObjCarga"] != null)
                        {
                            ret = cdBLL.ImportarDados((CargaDados)Session["ObjCarga"], dt);
                        }

                        if (ret)
                        {
                            ListaTodos();
                            MostraMensagemTelaUpdatePanel(upSimulacao, " Arquivo Carregado com sucesso\\n\\nQuantidade de linhas importados " + dt.Rows.Count + " registros");
                        }
                    }
                    catch (Exception ex)
                    {
                        MostraMensagemTelaUpdatePanel(upSimulacao, "Atenção\\n\\nO arquivo não pôde ser carregado.\\nMotivo:\\n" + ex.Message);
                    }
                    finally
                    {
                        FileUploadControl.FileContent.Dispose();
                        FileUploadControl.FileContent.Flush();
                        FileUploadControl.PostedFile.InputStream.Flush();
                        FileUploadControl.PostedFile.InputStream.Close();
                    }
                }
                else
                {
                    MostraMensagemTelaUpdatePanel(upSimulacao, "Atenção\\n\\nCarregue apenas arquivos Excel 2007 (.xlsx) ou superior!");
                }
            }

            else
            {
                MostraMensagemTelaUpdatePanel(upSimulacao, "Atenção\\n\\nSelecione um Arquivo para continuar!");
            }
        }
示例#24
0
 protected void UploadButton_Click(object sender, EventArgs e)
 {
     if (FileUploadControl.HasFile)
     {
         try
         {
             if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
             {
                 if (FileUploadControl.PostedFile.ContentLength < 1024000)
                 {
                     string  filename = Path.GetFileName(FileUploadControl.FileName);
                     Boolean movement = Boolean.Parse(movementRadioButton.SelectedValue);
                     FileUploadControl.SaveAs(Server.MapPath("~/Uploads/") + filename);
                     StatusLabel.Text = "Upload status: File uploaded!";
                     // Open DataBase connection and send to DB
                     sendToDB("~/Uploads/" + filename, movement);
                 }
                 else
                 {
                     StatusLabel.Text = "Upload status: The file has to be less than 1000 kb!";
                 }
             }
             else
             {
                 StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
             }
         }
         catch (Exception ex)
         {
             StatusLabel.Text = "Upload status: The file could not be uploaded: " + ex.Message;
         }
     }
 }
示例#25
0
 protected void UploadButton_Click(object sender, EventArgs e)
 {
     if (FileUploadControl.HasFile)
     {
         try
         {
             if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
             {
                 if (FileUploadControl.PostedFile.ContentLength < 10240000)
                 {
                     string filename = System.IO.Path.GetFileName(FileUploadControl.FileName);
                     FileUploadControl.SaveAs(Server.MapPath("/Cloud") + filename);
                     StatusLabel.Text = "Upload status: File uploaded!";
                 }
                 else
                 {
                     StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
                 }
             }
             else
             {
                 StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
             }
         }
         catch (Exception ex)
         {
             StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
         }
     }
 }
 protected void btnRegisterUser_Click(object sender, EventArgs e)
 {
     if (FileUploadControl.HasFile)
     {
         try
         {
             if (FileUploadControl.PostedFile.ContentType == "image/jpeg" || FileUploadControl.PostedFile.ContentType == "image/png")
             {
                 if (FileUploadControl.PostedFile.ContentLength < 102400)
                 {
                     string fileName = Path.GetFileName(FileUploadControl.FileName);
                     FileUploadControl.SaveAs(MapPath("~/UploadFiles/") + fileName);
                     tree.insertar(new User(txtNombreCompleto.Text, txtEmail.Text,
                                            txtPassword.Text, txtUserName.Text, txtTelefono.Text, MapPath("~/UploadFiles/") + fileName));
                 }
             }
             else
             {
                 ErrorMessage.Visible = true;
                 FailureText.Text     = "Solo se pueden imagenes jpg :'v";
             }
         } catch
         {
             ErrorMessage.Visible = true;
             FailureText.Text     = "Hubo un error de procesamiento, contacte con el administrador!";
         }
     }
 }
        protected void Upload(ColorItem item)
        {
            try
            {
                if (FileUploadControl.HasFile)
                {
                    string directory = Server.MapPath("~/images/palette/");
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    string newFileName = String.Format("{0}{1}{2}", directory, item.ColorID,
                                                       Path.GetExtension(FileUploadControl.FileName));
                    if (File.Exists(newFileName))
                    {
                        File.Delete(newFileName);
                    }

                    FileUploadControl.SaveAs(newFileName);
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
示例#28
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                try
                {
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(Server.MapPath("images/") + filename);
                    StatusLabel.Text = "Upload status: File uploaded!";
                    using (MySqlConnection connection = new MySqlConnection("Database=findsmth_;Data Source=localhost;User Id=root;Password=ibrahim220"))
                    {
                        using (MySqlCommand command = connection.CreateCommand())
                        {
                            connection.Open();
                            command.CommandType = CommandType.Text;

                            string n1 = String.Format("{0}", Request.Form["urunAd"]);
                            string n2 = items12.SelectedItem.ToString();
                            string n3 = Session["username"].ToString();
                            string n4 = String.Format("{0}", Request.Form["urunAciklama"]);

                            //Ürünler kısmında görünen bar 150 karakter sınırı ekleme
                            string n12 = "";
                            if (n4.Length < 100)
                            {
                                n12 = n4.ToString();
                            }
                            else
                            {
                                for (int i = 0; i < 100; i++)
                                {
                                    n12 += n4[i].ToString();
                                }
                            }

                            string n5 = "images/" + filename.ToString();


                            //adres bolumu
                            string n6  = String.Format("{0}", Request.Form["mahalle"]);
                            string n7  = String.Format("{0}", Request.Form["cadde"]);
                            string n8  = String.Format("{0}", Request.Form["numara"]);
                            string n9  = String.Format("{0}", Request.Form["sehir"]);
                            string n10 = String.Format("{0}", Request.Form["ilce"]);

                            string n11 = n6 + "+" + n7 + "+" + n8 + "+" + n9 + "+" + n10;
                            command.CommandText = "insert into paylasimlar(paylasimAdi, paylasimTuru, kadi, urunAciklama, begeni, url, adres, urunAciklamaHalf) Values('" + n1 + "','" + n2 + "','" + n3 + "','" + n4 + "','0','" + n5 + "','" + n11 + "', '" + n12 + "')";
                            command.ExecuteNonQuery();
                            connection.Close();
                            Response.Redirect("homepage.aspx");
                        }
                    }
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
        protected void saveButton_Click(object sender, EventArgs e)
        {
            string[] validFileTypes = { ".png", ".jpg", ".jpeg", ".gif", "svg" };
            string   ext            = System.IO.Path.GetExtension(FileUploadControl.PostedFile.FileName);

            bool isValidFile = false;

            for (int i = 0; i < validFileTypes.Length; i++)

            {
                if (ext.ToLower().Equals(validFileTypes[i]))
                {
                    isValidFile = true;

                    break;
                }
            }
            string errorMsg = "Successfull";

            if (isValidFile)
            {
                try
                {
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    string filePath = Server.MapPath("~/LinkImage/") + DateTime.Now.ToString("ddMMyyyyhhmmss") + filename.Substring(filename.LastIndexOf("."));
                    FileUploadControl.SaveAs(filePath);
                    Dictionary <string, object> inputDic = new Dictionary <string, object>();
                    inputDic.Add("puser_flag", linkUserDropDownListChosen.SelectedValue);
                    inputDic.Add("plink_title", linkTitleTextBox.Text.Trim());
                    inputDic.Add("pcatg_id", categoryDropDownListChosen.SelectedValue);
                    inputDic.Add("plink_url", urlTextBox.Text.Trim());
                    inputDic.Add("plink_img_url", filePath);
                    inputDic.Add("pmake_by", "Admin");
                    try
                    {
                        DataTable dt = linkManager.AddLink(inputDic);
                        errorMsg = "Successfully saved";
                    }
                    catch (Exception ex)
                    {
                        errorMsg = "Error Occured. Enter input data properly";
                    }
                }
                catch (Exception ex)
                {
                    errorMsg = "File Upload Error";
                }
            }
            else
            {
                errorMsg = "Upload Only Image File (.png, .jpg, .jpeg, .svg, .gif)";
            }

            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + errorMsg + "'); window.location='" +
                                               Request.ApplicationPath + "/UI/LinkEntry.aspx';", true);

            //Response.Redirect("LinkEntry.aspx");
        }
示例#30
0
    protected void UploadButton_Click(object sender, EventArgs e)
    {
        if (FileUploadControl.HasFile)
        {
            Session["category"] = CategoryList.SelectedValue.ToString();
            string FileName = FileUploadControl.PostedFile.FileName;
            Int64  FileSize = FileUploadControl.PostedFile.ContentLength;

            string FileExtension = FileName.Substring(FileName.LastIndexOf('.'));

            if (!String.Equals(FileExtension, ".pdf", StringComparison.OrdinalIgnoreCase))
            {
                StatusLabel.Text = "Upload status: Sorry, only '.pdf' files uploading is allowed";
            }
            else if (String.Equals(FileExtension, ".aspx", StringComparison.OrdinalIgnoreCase) || String.Equals(FileExtension, ".asp", StringComparison.OrdinalIgnoreCase))
            {
                StatusLabel.Text = "Upload status: Sorry, '.aspx' or '.asp' file uploading is not allowed";
            }
            else
            {
                string        Path      = Server.MapPath("~") + "FILES\\" + Session["category"].ToString();
                DirectoryInfo Directory = new DirectoryInfo(Path);
                if (!Directory.Exists)
                {
                    bool Created = CreateDirectory(Session["category"].ToString());
                    if (!Created)
                    {
                        StatusLabel.Text = "CRITICAL ERROR: User folder could not be created!";
                        return;
                    }
                }
                int StatusUpdateDB = AddFileToDatabase(Session["category"].ToString(), FileName, FileSize);
                Path += "\\";

                if (StatusUpdateDB == 0)
                {
                    FileUploadControl.SaveAs(Path + FileName);
                    StatusLabel.Text = "File uploaded successfully";
                }

                else if (StatusUpdateDB == 1)
                {
                    StatusLabel.Text = "Updoad Failed!<br />Reason: You have another file with the same name!";
                }

                else if (StatusUpdateDB == 2)
                {
                    StatusLabel.Text = "Updoad Failed!<br />Reason: Table \"UserInfo\" could not be updated";
                }

                else if (StatusUpdateDB == 3)
                {
                    StatusLabel.Text = "Updoad Failed!<br />Reason: Table \"Files\" could not be updated";
                }
            }
            StatusLabel.Visible = true;
        }
    }