protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
        {
            var filename = Page.Server.MapPath("~/Uploads/ProjectDocs/" + Path.GetFileName(e.FileName));

            // Proposal Document
            AjaxFileUpload1.SaveAs(filename);
        }
Example #2
0
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            FileInfo fi  = new FileInfo(e.FileName);
            string   ext = fi.Extension;

            string[] data = HttpUtility.UrlDecode(Request.Cookies["asp_act"].Value.ToString()).Split('|');
            if (data[1] == "2")
            {
                string fileID   = Fn.ExenID("INSERT INTO tblEmpDocs (EmpID,FileTitle, FileExt) VALUES (" + data[0] + ", '" + fi.Name + "', '" + ext + "');select SCOPE_IDENTITY()");
                string filePath = Server.MapPath("~") + "/Uploads/EmpDocuments/" + fileID + ext;
                AjaxFileUpload1.SaveAs(filePath);
            }
            else
            {
                Fn.Exec(@"UPDATE tblEmployee SET PhotoExtension='" + ext + "' WHERE EmpID=" + data[0]);
                string filePath = Server.MapPath("~") + "/Uploads/EmployeePhoto/" + data[0] + ext;
                AjaxFileUpload1.SaveAs(filePath);
                if (fi.Extension.ToUpper() == ".JPEG" || fi.Extension.ToUpper() == ".JPG" || fi.Extension.ToUpper() == ".BMP" || fi.Extension.ToUpper() == ".PNG" || fi.Extension.ToUpper() == ".GIF")
                {
                    Bitmap Thumbnail       = CreateThumbnail(filePath, 32, 32);
                    string SaveAsThumbnail = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~") + "/Uploads/EmployeePhoto/", Convert.ToString(data[0]) + "A" + fi.Extension);
                    Thumbnail.Save(SaveAsThumbnail);
                }

                if (fi.Extension.ToUpper() == ".JPEG" || fi.Extension.ToUpper() == ".JPG" || fi.Extension.ToUpper() == ".BMP" || fi.Extension.ToUpper() == ".PNG" || fi.Extension.ToUpper() == ".GIF")
                {
                    Bitmap Thumbnail       = CreateThumbnail(filePath, 75, 75);
                    string SaveAsThumbnail = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~") + "/Uploads/EmployeePhoto/", Convert.ToString(data[0]) + "B" + fi.Extension);
                    Thumbnail.Save(SaveAsThumbnail);
                }
            }
        }
Example #3
0
        /**
         * Name:         protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
         * Description:  This function allows the image uploader to succesfully save to the Images folder.
         * Arguments:    sender: Not used.
         *               e: Gets the filename of the selected image.
         * Return:       Nothing is returned.
         * Author:       David Stoddard
         * Date:         16/04/2015
         **/
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            string filename    = e.FileName;
            string strDestPath = Server.MapPath(strImagesPath);

            AjaxFileUpload1.SaveAs(@strDestPath + filename);
        }
Example #4
0
    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        string filename = Path.GetFileName(e.FileName);
        string ruta     = Server.MapPath("~/TMP");

        // Si el directorio no existe, crearlo
        if (!Directory.Exists(ruta))
        {
            Directory.CreateDirectory(ruta);
        }

        string archivo = String.Format("{0}\\{1}", ruta, filename);

        // Verificar que el archivo no exista
        if (File.Exists(archivo))
        {
            lblError.Text = (String.Format("Ya existe Documento con nombre\"{0}\".", filename));
        }
        else
        {
            AjaxFileUpload1.SaveAs(ruta + "\\" + filename);
        }
        Session["archivo"] = ruta + "\\" + filename;
        Session["carga"]   = filename;
        e.DeleteTemporaryData();
    }
        protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            // Generate file path
            saveAsfilePath = selectedfilePath + e.FileName;

            // Save upload file to the file system
            AjaxFileUpload1.SaveAs(MapPath(saveAsfilePath));
        }
Example #6
0
        protected void File_Upload(object sender, AjaxFileUploadEventArgs e)
        {
            string filename = e.FileName;

            string strDestPath = Server.MapPath("Input/");

            AjaxFileUpload1.SaveAs(@strDestPath + filename);
        }
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            // Generate file path
            string filePath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "/img/galeria/" + System.IO.Path.GetFileName(e.FileName);

            // Save upload file to the file system
            AjaxFileUpload1.SaveAs(filePath);
        }
        protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
        {
            var id = _id;

            var filename = Page.Server.MapPath("~/Uploads/CVS/" + Path.GetFileName(e.FileName));

            //CV
            AjaxFileUpload1.SaveAs(filename);
        }
Example #9
0
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            string fname = DateTime.Now.ToString("yyyMMddHHmmss") + "." + e.FileName.Split('.')[1];

            Fn.Exec("INSERT INTO TblVoucherDoc(VoucherID, DocName, DocPath, DocExt)VALUES (" + Request.Cookies["VID"].Value + ", '" + e.FileName.Split('.')[0] + "', '" + fname + "', '" + e.FileName.Split('.')[1] + "')");
            string filePath = Server.MapPath("~") + "/Vouchers/" + fname;

            AjaxFileUpload1.SaveAs(filePath);
        }
Example #10
0
    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        TESTCASE_CHECKSUM tbl      = new TESTCASE_CHECKSUM();
        string            filePath = "C:/Users/chritan/Documents/turtle/output/" + e.FileName;

        AjaxFileUpload1.SaveAs(filePath);

        tbl.read_checksums(filePath);
    }
Example #11
0
 protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
 {
     if (e.FileSize > 10)
     {
         string filePath = e.FileName;
         AjaxFileUpload1.SaveAs(Server.MapPath(filePath));
     }
     else
     {
     }
 }
Example #12
0
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            string TenAnh = e.FileName;

            String[] strTmp = TenAnh.Split('.');
            TenAnh  = DateTime.Now.ToFileTimeUtc().ToString();
            TenAnh += "." + strTmp[1];
            string strDestPath = Server.MapPath("~/imagesTmp/");

            AjaxFileUpload1.SaveAs(@strDestPath + TenAnh);
            anh = "imagesTmp/" + TenAnh;
        }
Example #13
0
    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        //count = count + 1;



        string fileNameWithPath = Server.MapPath("~/test/") + e.FileName.ToString();



        AjaxFileUpload1.SaveAs(fileNameWithPath);
    }
Example #14
0
 protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
 {
     try
     {
         string path = Server.MapPath("../../../Content/imgSub/") + e.FileName.ToString();
         Session["nombrefoto"] = e.FileName.ToString();
         AjaxFileUpload1.SaveAs(path);
     }
     catch
     {
         Session["nombrefoto"] = "";
         Mensaje("publicacion de la foto", false);
         btnCargar.Enabled = false;
     }
 }
Example #15
0
 protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
 {
     try
     {
         string savePath = MapPath("~/Images/" + e.FileName);
         // dont save file & return if condition not matched.
         if (e.FileSize > 72000)     // use same condition in client side code
         {
             return;
         }
         AjaxFileUpload1.SaveAs(savePath);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #16
0
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            string        guid     = Guid.NewGuid().ToString();
            UploadSession obj      = (UploadSession)Session["upload"];
            string        filename = Server.MapPath("/Albums/" + obj.Folder + "/" + guid + ".JPG");

            AjaxFileUpload1.SaveAs(filename);
            SqlParameter pID = new SqlParameter("AlbumID", SqlDbType.Int);

            pID.Value = obj.Id;
            SqlParameter pUrl = new SqlParameter("ImageUrl", SqlDbType.NVarChar);

            pUrl.Value = guid + ".jpg";
            SqlParameter insertedKey = new SqlParameter("AlbumDetailID", SqlDbType.Int);

            insertedKey.Direction = ParameterDirection.Output;
            string NewsID = DataAccessLayer.ExcuteNoneQueryHasOutput("Album_InsertAlbumDetail", "AlbumDetailID", pID, pUrl, insertedKey);
        }
Example #17
0
        protected void AjaxFileUpload1_UploadComplete1(object sender, AjaxFileUploadEventArgs e)
        {
            string TenAnh = e.FileName;

            String[] tmp = TenAnh.Split('.');
            TenAnh = tmp[0];
            string strDestPath = Server.MapPath("~/admin/images/");
            String TenImage    = macay.ToString() + "_" + DateTime.Now.ToFileTimeUtc().ToString();
            String url         = "images/" + TenImage + "." + tmp[1];

            if (dao.anh_caythuoc.insert_anh(macay, TenAnh, url))
            {
                AjaxFileUpload1.SaveAs(@strDestPath + TenImage + "." + tmp[1]);
            }
            else
            {
                lbDisplay.Text = "Looix";
            }
        }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        string filePath        = MapPath("~/App_Data/" + e.FileName);
        string fileContentType = e.ContentType;
        int    fileSize        = e.FileSize;
        string fileName        = e.FileName;
        string path            = MapPath("~/App_Data/" + e.FileName);

        AjaxFileUpload1.SaveAs(path);
        //e.PostedUrl = string.Format("?preview=1&fileId={0}", e.FileId);

        FileInfo fileInfo = new FileInfo(filePath);
        string   ID       = Path.GetFileNameWithoutExtension(path);

        // The byte[] to save the data in
        byte[] data = new byte[fileInfo.Length];

        // Load a filestream and put its content into the byte[]
        using (FileStream fs = fileInfo.OpenRead())
        {
            fs.Read(data, 0, data.Length);
        }

        byte[] EncryptData     = CryptoImage.EncryptBytes(data);
        int    EncryptfileSize = EncryptData.Length;

        System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection();

        sqlConnection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
        String SqlCmdText1 = "UPDATE VisitorsCard SET VisImage =@VisImage,VisImageContentType=@VisImageContentType,VisImageLength=@VisImageLength WHERE VisIdentityNo = @VisIdentityNo";

        System.Data.SqlClient.SqlCommand sqlCmdObj1 = new System.Data.SqlClient.SqlCommand(SqlCmdText1, sqlConnection);

        sqlCmdObj1.Parameters.Add("@VisIdentityNo", System.Data.SqlDbType.VarChar, 100).Value       = ID;
        sqlCmdObj1.Parameters.Add("@VisImage", System.Data.SqlDbType.Binary, EncryptfileSize).Value = EncryptData;
        sqlCmdObj1.Parameters.Add("@VisImageContentType", System.Data.SqlDbType.VarChar, 255).Value = fileContentType;
        sqlCmdObj1.Parameters.Add("@VisImageLength", System.Data.SqlDbType.Int).Value = EncryptfileSize;

        sqlConnection.Open();
        sqlCmdObj1.ExecuteNonQuery();
        sqlConnection.Close();
    }
Example #19
0
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxFileUploadEventArgs e)
        {
            string str_filename, str_field;
            string path = Server.MapPath("~/videos/") + e.FileName;

            str_filename = e.FileName;
            string str_file_save  = str_filename.Replace(".wmv", ".mp4");
            string str_filesize   = e.FileSize.ToString();
            Int32  str_filesizemb = Convert.ToInt32(str_filesize) / 1024;

            str_field = e.FileId;

            //using (var insert_material = new db_transcriptEntities())
            //{

            //    var items_user = new inf_material
            //    {
            //        expediente = "00001",
            //        sesion = "001",
            //        archivo = str_filename,
            //        bits = Convert.ToInt32(str_filesizemb),
            //        fecha_registro = DateTime.Now,
            //        id_estatus_material = 1,
            //        id_usuario = id_user,

            //    };
            //    insert_material.inf_material.Add(items_user);
            //    insert_material.SaveChanges();
            //}

            AjaxFileUpload1.SaveAs(path);

            //ReturnVideo(path);
            var ffMpeg = new NReco.VideoConverter.FFMpegConverter();

            ffMpeg.ConvertMedia(path, "videos/" + str_file_save, Format.mp4);
            lbl_mnsj.Visible = true;
            lbl_mnsj.Text    = "Videa a mp4 con Exito";
            //Session["ss_id_user"] = id_user;
        }
Example #20
0
    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        bool   ret      = false;
        string filePath = Config.GetTempPath + e.FileName;

        try
        {
            TESTCASE_CHECKSUMS_VIEW tbl = new TESTCASE_CHECKSUMS_VIEW();
            AjaxFileUpload1.SaveAs(filePath);

            ret = tbl.update_checksums(Master.CurrentUserName, filePath);
        }
        catch (Exception ex)
        {
            using (StreamWriter writer = new StreamWriter(filePath, true))
            {
                writer.WriteLine("Message :" + ex.Message + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                                 "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
        }
    }
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            string fileNametoupload = Server.MapPath("~/AjaxUpload/") + e.FileName.ToString();

            AjaxFileUpload1.SaveAs(fileNametoupload);
        }
        protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
        {
            string datetime     = DateTime.Now.ToFileTimeUtc().ToString();
            string filename     = "";
            string originalfile = "";

            try
            {
                String extension = Path.GetExtension(file.FileName);
                filename     = Session["userid"].ToString() + "_" + datetime + extension;
                originalfile = file.FileName;
                // Limit preview file for file equal or under 4MB only, otherwise when GetContents invoked
                // System.OutOfMemoryException will thrown if file is too big to be read.
                if (file.FileSize <= 1024 * 1024 * 50)
                {
                    Session["fileContentType_" + file.FileId] = file.ContentType;
                    Session["fileContents_" + file.FileId]    = file.GetContents();

                    // Set PostedUrl to preview the uploaded file.
                    // file.PostedUrl = string.Format("?preview=1&fileId={0}", file.FileId);
                    file.PostedUrl = "downloads.png";
                }
                else
                {
                    file.PostedUrl = "downloads.png";
                }


                string directory = @"webfile/" + Session["companyid"].ToString() + "/";
                // Since we never call the SaveAs method(), we need to delete the temporary fileß
                string dir = Server.MapPath(directory);
                if (!Directory.Exists(Server.MapPath(directory)))
                {
                    Directory.CreateDirectory(Server.MapPath(directory));
                }
                AjaxFileUpload1.SaveAs(MapPath(directory + filename), true);

                if (Session["file"] == null)
                {
                    tblfile = createtable();
                }
                else
                {
                    tblfile = (DataTable)Session["file"];
                }

                itemdr = tblfile.NewRow();



                itemdr["originalname"] = originalfile;

                itemdr["savename"] = filename;
                itemdr["ext"]      = extension;
                tblfile.Rows.Add(itemdr);

                Session["file"] = tblfile;

                file.DeleteTemporaryData();
            }
            catch
            {
            }
        }
Example #23
0
    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        string filePath = Request.PhysicalApplicationPath + @"uploads\" + e.FileName;

        AjaxFileUpload1.SaveAs(filePath);
    }
Example #24
0
        //Dette køres hver gang en fil bliver uploadet - Vi kigger på om der er plads til flere billeder og giver billedet det rigtige navn (max 8 billeder)
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxFileUploadEventArgs e)
        {
            string ID       = Request.QueryString["id"];
            string filename = e.FileName;

            if (filename.Contains(".jpg") || filename.Contains(".jpeg") || filename.Contains(".png"))
            {
                if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/pic1.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/pic1.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/pic2.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/pic2.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/pic3.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/pic3.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/pic4.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/pic4.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/pic5.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/pic5.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/pic6.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/pic6.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/pic7.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/pic7.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/pic8.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/pic8.jpg"));
                }
                else
                {
                    labError.Text = "Du må max uploade 8 billeder i alt!";
                }
            }
            //Vi kigger også efter en videofil
            else if (filename.Contains(".mp4"))
            {
                if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/vid1.mp4"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/vid1.mp4"));
                }
                else
                {
                    labError.Text = "Du må max uploade 1 video!";
                }
            }
            //Og også efter en lydfil
            else if (filename.Contains(".mp3"))
            {
                if (!(System.IO.File.Exists(Server.MapPath("/Uploads/" + ID + "/aud1.mp3"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/" + ID + "/aud1.mp3"));
                }
                else
                {
                    labError.Text = "Du må max uploade 1 lydfil!";
                }
            }
        }
Example #25
0
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxFileUploadEventArgs e)
        {
            string filename = e.FileName;

            if (filename.Contains(".jpg") || filename.Contains(".jpeg") || filename.Contains(".png"))
            {
                if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/pic1.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/pic1.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/pic2.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/pic2.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/pic3.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/pic3.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/pic4.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/pic4.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/pic5.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/pic5.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/pic6.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/pic6.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/pic7.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/pic7.jpg"));
                }
                else if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/pic8.jpg"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/pic8.jpg"));
                }
                else
                {
                    labError.Text = "Du må max uploade 8 billeder i alt!";
                }
            }
            else if (filename.Contains(".mp4"))
            {
                if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/vid1.mp4"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/vid1.mp4"));
                }
                else
                {
                    labError.Text = "Du må max uploade 1 video!";
                }
            }
            else if (filename.Contains(".mp3"))
            {
                if (!(System.IO.File.Exists(Server.MapPath("/Uploads/1/aud1.mp3"))))
                {
                    AjaxFileUpload1.SaveAs(Server.MapPath("./Uploads/1/aud1.mp3"));
                }
                else
                {
                    labError.Text = "Du må max uploade 1 lydfil!";
                }
            }
        }
Example #26
0
    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxFileUploadEventArgs e)
    {
        if (Session["id"] != null && Session["id"].ToString() != "")
        {
            long           ID       = long.Parse(Session["id"].ToString());
            Productpicture objpp    = new Productpicture();
            string         filename = Session["id"].ToString() + "_" + System.IO.Path.GetFileName(e.FileName);
            //System.Drawing.Image image = System.Drawing.Image.FromStream(filename, true, true);
            // yourImage = resizeImage(yourImage, new Size(50, 50));
            string strUploadPath = "~/Images/";
            string filepath      = strUploadPath + filename;
            AjaxFileUpload1.SaveAs(Server.MapPath(strUploadPath + filename));
            objpp.PicturePath = filepath;
            objpp.ProductID   = ID;


            if (Session["up1"] == null)
            {
                Session["up1"] = filepath;
            }
            else if (Session["up1"] == "")
            {
                Session["up1"] = filepath;
            }
            else if (Session["up2"] == null)
            {
                Session["up2"] = filepath;
            }
            else if (Session["up2"] == "")
            {
                Session["up2"] = filepath;
            }
            else if (Session["up3"] == null)
            {
                Session["up3"] = filepath;
            }
            else if (Session["up3"] == "")
            {
                Session["up3"] = filepath;
            }
            else if (Session["up4"] == null)
            {
                Session["up4"] = filepath;
            }
            else if (Session["up4"] == "")
            {
                Session["up4"] = filepath;
            }
            else if (Session["up5"] == null)
            {
                Session["up5"] = filepath;
            }
            else if (Session["up5"] == "")
            {
                Session["up5"] = filepath;
            }
            else if (Session["up6"] == null)
            {
                Session["up6"] = filepath;
            }
            else if (Session["up6"] == "")
            {
                Session["up6"] = filepath;
            }
        }
    }
Example #27
0
    //Image Upload with ajax
    protected void ajaxUpload1_OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        MembershipUser currentUser   = Membership.GetUser();
        Guid           currentUserId = (Guid)currentUser.ProviderUserKey;
        //  e.Command.Parameters["@UserId"].Value = currentUserId;


        //generate random image name
        Random rand            = new Random();
        string numRandom       = rand.Next(13123, 444128312).ToString();
        string ranFileNamePath = "~/UserUploads/" + numRandom + ".jpg";

        //CHECK THIS   !!!
        while (File.Exists(ranFileNamePath))
        {
            numRandom = rand.Next(13123, 444128312).ToString();
        }


        string ProfileName = currentUser.ToString();


        // string ImageName = ProfileName + "/" + numRandom;



        string ConnectionString = Checks.getConnectionString();

        string insertSqlUpload = "INSERT INTO Cus_Upload(UserId, ImageName, ProfileName, Folder, NumOfLikes, NumOfViews) VALUES(@UserId, @ImageName, @ProfileName, @Folder, @NumOfLikes, @NumOfViews)";


        using (SqlConnection myConnection = new SqlConnection(ConnectionString))
        {
            myConnection.Open();
            SqlCommand Upload = new SqlCommand(insertSqlUpload, myConnection);
            Upload.Parameters.AddWithValue("@UserId", currentUserId);
            Upload.Parameters.AddWithValue("@ImageName", numRandom);
            Upload.Parameters.AddWithValue("@ProfileName", currentUser.ToString());
            Upload.Parameters.AddWithValue("@Folder", currentUser.ToString());
            Upload.Parameters.AddWithValue("@NumOfLikes", 0);
            Upload.Parameters.AddWithValue("@NumOfViews", 0);


            Upload.ExecuteNonQuery();
        }


        // Generate file path
        string filePath = "~/UserUploads/" + numRandom + ".jpg";

        // Save upload file to the file system
        AjaxFileUpload1.SaveAs(MapPath(filePath));

        //IMAGE RESIZER
        string FileToResize  = Server.MapPath(filePath);
        string FileToResize2 = Server.MapPath(filePath);



        Bitmap originalBMP  = new Bitmap(FileToResize);
        Bitmap originalBMP2 = new Bitmap(FileToResize2);

        // Calculate the new image dimensions
        decimal origWidth = originalBMP.Width;

        if (origWidth >= 820)
        {
            decimal origHeight       = originalBMP.Height;
            decimal sngRatio         = origWidth / origHeight;
            int     newWidth2        = 280;
            int     newWidth         = 820;
            decimal newHeight_temp   = newWidth / sngRatio;
            decimal newHeight2_temp2 = newWidth2 / sngRatio;
            int     newHeight        = Convert.ToInt32(newHeight_temp);
            int     newHeight2       = Convert.ToInt32(newHeight2_temp2);


            // Create a new bitmap which will hold the previous resized bitmap
            Bitmap newBMP  = new Bitmap(originalBMP, newWidth, newHeight);
            Bitmap newBMP2 = new Bitmap(originalBMP2, newWidth2, newHeight2);
            // Create a graphic based on the new bitmap
            Graphics oGraphics  = Graphics.FromImage(newBMP);
            Graphics oGraphics2 = Graphics.FromImage(newBMP2);
            // Set the properties for the new graphic file
            oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            // Draw the new graphic based on the resized bitmap
            oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
            oGraphics2.SmoothingMode = SmoothingMode.AntiAlias; oGraphics2.InterpolationMode = InterpolationMode.HighQualityBicubic;
            // Draw the new graphic based on the resized bitmap
            oGraphics2.DrawImage(originalBMP2, 0, 0, newWidth2, newHeight2);

            // Save the new graphic file to the server
            newBMP.Save(Server.MapPath("~/UserUploads/820/" + numRandom + ".jpg"));
            newBMP2.Save(Server.MapPath("~/UserUploads/280/" + numRandom + ".jpg"));
            // Once finished with the bitmap objects, we deallocate them.
            originalBMP.Dispose();
            newBMP.Dispose();
            oGraphics.Dispose();

            originalBMP2.Dispose();
            newBMP2.Dispose();
            oGraphics2.Dispose();
        }
        else
        {
            decimal origHeight = originalBMP.Height;
            decimal sngRatio   = origWidth / origHeight;
            int     newWidth2  = 280;

            decimal newHeight2_temp2 = newWidth2 / sngRatio;

            int newHeight2 = Convert.ToInt32(newHeight2_temp2);


            // Create a new bitmap which will hold the previous resized bitmap

            Bitmap newBMP2 = new Bitmap(originalBMP2, newWidth2, newHeight2);
            // Create a graphic based on the new bitmap

            Graphics oGraphics2 = Graphics.FromImage(newBMP2);


            oGraphics2.SmoothingMode = SmoothingMode.AntiAlias; oGraphics2.InterpolationMode = InterpolationMode.HighQualityBicubic;
            // Draw the new graphic based on the resized bitmap
            oGraphics2.DrawImage(originalBMP2, 0, 0, newWidth2, newHeight2);


            newBMP2.Save(Server.MapPath("~/UserUploads/280/" + numRandom + ".jpg"));
            // Once finished with the bitmap objects, we deallocate them.
            originalBMP.Save(Server.MapPath("~/UserUploads/820/" + numRandom + ".jpg"));

            originalBMP2.Dispose();
            newBMP2.Dispose();
            oGraphics2.Dispose();
        }
    }
        protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
        {
            if (hidisvalid.Value == "")
            {
                string datetime     = DateTime.Now.ToFileTimeUtc().ToString();
                string filename     = "";
                string originalfile = "";
                if ((Convert.ToDouble(hidcurfilesize.Value) + file.FileSize) <= Convert.ToDouble(hidfilesize.Value) * 1024 * 1024)
                {
                    try
                    {
                        String extension = Path.GetExtension(file.FileName);
                        filename     = datetime + extension;
                        originalfile = file.FileName;
                        // Limit preview file for file equal or under 4MB only, otherwise when GetContents invoked
                        // System.OutOfMemoryException will thrown if file is too big to be read.
                        if (file.FileSize <= Convert.ToDouble(hidfilesize.Value) * 1024 * 1024)
                        {
                            Session["fileContentType_" + file.FileId] = file.ContentType;
                            Session["fileContents_" + file.FileId]    = file.GetContents();

                            // Set PostedUrl to preview the uploaded file.
                            // file.PostedUrl = string.Format("?preview=1&fileId={0}", file.FileId);
                            file.PostedUrl = "downloads.png";
                        }
                        else
                        {
                            file.PostedUrl = "downloads.png";
                        }

                        hidcurfilesize.Value = (Convert.ToDouble(hidcurfilesize.Value) + file.FileSize).ToString();
                        string directory = @"webfile/emailfile/";
                        // Since we never call the SaveAs method(), we need to delete the temporary fileß
                        string dir = Server.MapPath(directory);
                        if (!Directory.Exists(Server.MapPath(directory)))
                        {
                            Directory.CreateDirectory(Server.MapPath(directory));
                        }
                        AjaxFileUpload1.SaveAs(MapPath(directory + filename), true);

                        if (Session["file"] == null)
                        {
                            tblfile = createtable();
                        }
                        else
                        {
                            tblfile = (DataTable)Session["file"];
                        }

                        itemdr = tblfile.NewRow();



                        itemdr["originalname"] = originalfile;

                        itemdr["savename"] = filename;
                        itemdr["ext"]      = extension;
                        tblfile.Rows.Add(itemdr);

                        Session["file"] = tblfile;

                        file.DeleteTemporaryData();
                    }
                    catch
                    {
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'> alert('File exceeds upload size limit');</script>", false);
                }

                //}
                //else
                //{
                //    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'> alert('The Files you are trying to send exceed the Max Limit.');</script>", false);

                //}
            }
        }
Example #29
0
        protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            try
            {
                Presentation gonderi = new Presentation();
                gonderi.CreatedDate = DateTime.Now.ToLocalTime();
                gonderi.IsActive    = true;
                gonderi.SubjectID   = Convert.ToInt32(Session["BolumId"]);
                gonderi.ClassroomID = Convert.ToInt32(Session["SinifId"]);
                gonderi.FileName    = e.FileName;
                int trainerid;
                if (Session["SuperUserId"] != null)
                {
                    trainerid = Convert.ToInt32(Session["SuperUserId"]);
                }
                else
                {
                    trainerid = Convert.ToInt32(Session["UserId"]);
                }
                Trainer gelen = kislem.TekGetir(trainerid);

                if (gelen != null)
                {
                    gonderi.TrainerID = gelen.Id;
                    gonderi.SectionID = Convert.ToInt32(gelen.SectionID);
                }
                string extension = e.FileName.Substring(e.FileName.LastIndexOf('.'));
                if (extension == ".txt" || extension == ".doc" || extension == ".pdf")
                {
                    gonderi.FileUrl = "/Files/Documents/" + e.FileName;
                    filePath        = "/Files/Documents/" + e.FileName;
                    AjaxFileUpload1.SaveAs(Server.MapPath(filePath));
                }
                else if (extension == ".jpg" || extension == ".png" || extension == ".gif" || extension == ".jpeg")
                {
                    gonderi.FileUrl = "/Files /Images / " + e.FileName;
                    filePath        = "/Files/Images/" + e.FileName;
                    AjaxFileUpload1.SaveAs(Server.MapPath(filePath));
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "uy3", "Bilgilendirme('Dosya biçimi desteklenmiyor','error');", true);
                }
                else if (extension == ".rar" || extension == ".zip")
                {
                    gonderi.FileUrl = "/Files/Archiver/" + e.FileName;
                    filePath        = "/Files/Archiver/" + e.FileName;
                    AjaxFileUpload1.SaveAs(Server.MapPath(filePath));
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "uy3", "Bilgilendirme('Dosya biçimi desteklenmiyor','error');", true);
                }


                if (islem.Ekle(gonderi))
                {
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "js", "Bilgilendirme('Sınıf başarıyla eklendi.','success');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "js", "Bilgilendirme('HATA.','success');", true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            string path = Server.MapPath("~/Uploads/") + e.FileName;

            AjaxFileUpload1.SaveAs(path);
        }