Click here to Skip to main content
16,007,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to autopostback is true in fileuploader and priview to image tool Atomatically
Posted

C#
protected void Upload_Button(object sender, EventArgs e)
   {
       string imgName = FileUpload1.FileName;
       string imgPath = "YourFolderName/" + imgName;// Uploads/image1
       int imgSize = FileUpload1.PostedFile.ContentLength;
       if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
       {
           FileUpload1.SaveAs(Server.MapPath(imgPath));
           ImageControl.ImageUrl = "folderName/" + imgPath;//Decktop/uploads/image1
           lblUpload.ForeColor = System.Drawing.Color.Green;
           lblUpload.Text = "File uploaded successfully....";
       }
       else
       {
           lblUpload.ForeColor = System.Drawing.Color.Red;
           lblUpload.Text = "File not uploaded ";
       }
   }
 
Share this answer
 
C#
if (UploadUserPhoto.PostedFile != null)
{
    string myMap = MapPath("~/").ToLower();
    Random r = new Random();
    int next = r.Next();
    string ImageName = UploadUserPhoto.PostedFile.FileName;

 extension = ImageName.Substring(ImageName.LastIndexOf(".")).ToLower();
    if (extension == ".gif" || extension == ".png" || extension == ".jpg" || extension== ".jpeg" || extension == ".bmp")
    {
        string ImageSaveURL = myMap + "UserImage/" + next + extension;
        try
        {
            UploadUserPhoto.PostedFile.SaveAs(ImageSaveURL);
string RegisterQuery = "INSERT INTO [ImageUpload] (Email,Password,Name,Country,Description,ImageName) VALUES('" + TextBoxEmail.Text + "','" + TextBoxPassword.Text + "','" + TextBoxName.Text + "','" + TextBoxCountry.Text + "','" + TextBoxComment.Text + "','" + next + extension + "')";
            dbClass.ConnectDataBaseToInsert(RegisterQuery);
            Response.Redirect("~/login.aspx");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    else
    {
    }
 
Share this answer
 

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