public int InsertImage(UploadedFile file, int userID)
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TelerikConnectionString35"].ConnectionString;

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                string cmdText = "INSERT INTO AsyncUploadImages VALUES(@ImageData, @ImageName, @UserID) SET @Identity = SCOPE_IDENTITY()";
                SqlCommand cmd = new SqlCommand(cmdText, conn);

                byte[] imageData = GetImageBytes(file.InputStream);

                SqlParameter identityParam = new SqlParameter("@Identity", SqlDbType.Int, 0, "ImageID");
                identityParam.Direction = ParameterDirection.Output;

                cmd.Parameters.AddWithValue("@ImageData", imageData);
                cmd.Parameters.AddWithValue("@ImageName", file.GetName());
                cmd.Parameters.AddWithValue("@UserID", userID);

                cmd.Parameters.Add(identityParam);

                conn.Open();
                cmd.ExecuteNonQuery();

                return (int)identityParam.Value;
            }
        }
Exemple #2
0
        private string SaveMyFile(UploadedFile uploadedFile, int cableway_id, DateTime visit_dt)
        {
            string status_msg   = "fail";
            string savePath     = Server.MapPath("~/Files/Cableways/");
            string fullfileName = string.Format("{0:yyyyMMdd}", visit_dt) + "_" + uploadedFile.GetName();
            string dirToCheck   = savePath + cableway_id.ToString() + "\\";
            string pathToCheck  = null;

            try
            {
                //Check to see if there's a pre-existing directory for this site ID
                if (!Directory.Exists(dirToCheck))
                {
                    //If it does not exist, create the site ID directory
                    Directory.CreateDirectory(dirToCheck);
                }

                pathToCheck = dirToCheck + fullfileName;

                if (File.Exists(pathToCheck))
                {
                    status_msg = "exists";
                }
                else
                {
                    uploadedFile.SaveAs(pathToCheck);
                    status_msg = fullfileName;
                }
            }
            catch (Exception ex)
            {
            }

            return(status_msg);
        }
    public int InsertImage(UploadedFile file, int userID, string text)
    {
        string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            string     cmdText = "INSERT INTO AsyncUploadImages VALUES(@ImageData, @ImageName, @UserID, @Text) SET @Identity = SCOPE_IDENTITY()";
            SqlCommand cmd     = new SqlCommand(cmdText, conn);

            byte[] imageData = GetImageBytes(file.InputStream);

            SqlParameter identityParam = new SqlParameter("@Identity", SqlDbType.Int, 0, "ImageID");
            identityParam.Direction = ParameterDirection.Output;

            cmd.Parameters.AddWithValue("@ImageData", imageData);
            cmd.Parameters.AddWithValue("@ImageName", file.GetName());
            cmd.Parameters.AddWithValue("@UserID", userID);
            cmd.Parameters.AddWithValue("@Text", text);

            cmd.Parameters.Add(identityParam);

            conn.Open();
            cmd.ExecuteNonQuery();

            return((int)identityParam.Value);
        }
    }
Exemple #4
0
        private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file)
        {
            const int total = 100;

            RadProgressContext progress = RadProgressContext.Current;

            for (int i = 0; i < total; i++)
            {
                progress.PrimaryTotal   = 1;
                progress.PrimaryValue   = 1;
                progress.PrimaryPercent = 100;

                progress.SecondaryTotal   = total;
                progress.SecondaryValue   = i;
                progress.SecondaryPercent = i;

                progress.CurrentOperationText = file.GetName() + " Empezando a procesar...";

                if (!Response.IsClientConnected)
                {
                    //Cancel button was clicked or the browser was closed, so stop processing
                    break;
                }

                //Stall the current thread for 0.1 seconds
                System.Threading.Thread.Sleep(100);
            }
        }
Exemple #5
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                //Validar que se haya subido un archivo
                if (AsyncUpload1.UploadedFiles.Count > 0)
                {
                    path = Server.MapPath(ConfigurationManager.AppSettings["DocumentPath"].ToString());

                    file = AsyncUpload1.UploadedFiles[0];

                    if (file.ContentLength < MaxTotalBytes)
                    {
                        file.SaveAs(path + file.GetName(), true);
                    }
                }
                lblFile.Text = file.GetName();
                cargarGrilla();
            }
            catch (Exception ex)
            {
                lblError.Text = "Error al Cargar Datos: Formato de Archivo no válido" + ex.Message;
                lblFile.Text  = string.Empty;
                rgImportarTransversales.DataSource = String.Empty;
                rgImportarTransversales.Rebind();
            }
            lblRegistro.Text = string.Empty;
        }
        protected override void Save(UploadedFile file)
        {
            var size      = file.ContentLength;
            var storeKey  = file.ServerKey;
            var name      = file.GetName();
            var extension = file.GetExtension();

            try
            {
                var directoryId = GetDirectoryId();
                var result      = ServiceContext.Invoke("addFile", (arg) =>
                {
                    arg["name"]        = name;
                    arg["storeKey"]    = storeKey;
                    arg["extension"]   = extension;
                    arg["size"]        = size;
                    arg["directoryId"] = directoryId;
                });
                this.Response.Write(result.GetCode(false, false));
            }
            catch (Exception ex)
            {
                Delete(storeKey);
                throw ex;
            }
        }
        protected void FileUploadFlightInfo_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            UploadedFile file = e.File;

            fileExtension = file.GetExtension();
            fileName      = file.GetName();
            path          = Server.MapPath("~/Upload/");
            file.SaveAs(path + fileName);
        }
        protected void btnGrabar_Click(object sender, EventArgs e)
        {
            StringBuilder sPath = new StringBuilder();

            sPath.Append(Server.MapPath("."));
            sPath.Append(@"\style\");

            //--- Sube Css al repositorio del sitio ---//
            string sExt;
            string sFile;

            sExt = ".css";
            rdUploadFileCss.AllowedFileExtensions = sExt.Split(new string[] { "," }, StringSplitOptions.None);
            if (rdUploadFileCss.UploadedFiles.Count > 0)
            {
                oUpload = rdUploadFileCss.UploadedFiles[0];
                oUpload.SaveAs(sPath.ToString() + oUpload.GetName());
            }
            //--- Sube Zip de imagenes al repositorio del sitio ---//
            sPath.Append(@"\images\");
            sExt = ".zip";
            rdUploadZip.AllowedFileExtensions = sExt.Split(new string[] { "," }, StringSplitOptions.None);
            if (rdUploadZip.UploadedFiles.Count > 0)
            {
                oUpload = rdUploadZip.UploadedFiles[0];
                sFile   = oUpload.GetName();
                oUpload.SaveAs(sPath.ToString() + sFile.ToString());

                if (sFile.IndexOf(".zip", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    //Descomprime Archivo Zip.
                    using (ZipFile oZip = ZipFile.Read(sPath.ToString() + sFile.ToString()))
                    {
                        foreach (ZipEntry oZipEntry in oZip)
                        {
                            oZipEntry.Extract(sPath.ToString(), ExtractExistingFileAction.OverwriteSilently);
                        }
                    }
                }
            }

            sPath = new StringBuilder();
            sPath.Append(Server.MapPath("."));
            sPath.Append(@"\style\");

            StreamWriter sw = File.CreateText(sPath.ToString() + "masterstyle.css");

            if (rdListAsignados.Items.Count > 0)
            {
                for (int i = 0; i < rdListAsignados.Items.Count; i++)
                {
                    sw.WriteLine("@import url(\"" + rdListAsignados.Items[i].Value + "\");");
                }
            }
            sw.Close();
        }
Exemple #9
0
 private string saveAsScan(string scanName, ref UploadedFile obj)
 {
     try
     {
         string Path    = getPathOfScan(scanName);
         string urlPath = Path + obj.GetName().improveFileName();
         System.IO.Directory.CreateDirectory(Server.MapPath(Path));
         return(urlPath);
     }
     catch (Exception ex)
     { return(""); }
 }
Exemple #10
0
        private string SaveFileIntoServer(UploadedFile file, string strGuid, string strPath)
        {
            fileExtension = file.GetExtension();
            string strRenameFilename = file.GetName();

            strRenameFilename = strRenameFilename.Replace(' ', '_');
            //string newFileName = advisorVo.advisorId + "_" + strGuid + "_" + strRenameFilename;
            string newFileName = strRenameFilename;

            // Save adviser repository file in the path
            file.SaveAs(strPath + "\\" + newFileName);
            return(newFileName);
        }
        protected void btnGrabar1_Click(object sender, EventArgs e)
        {
            try
            {
                string        sFile = string.Empty;
                StringBuilder sPath = new StringBuilder();
                sPath.Append(Server.MapPath("."));
                sPath.Append(@"\images\logos\");

                DBConn oConn = new DBConn();
                if (oConn.Open())
                {
                    foreach (string fileInputID in Request.Files)
                    {
                        UploadedFile file = UploadedFile.FromHttpPostedFile(Request.Files[fileInputID]);
                        if (file.ContentLength > 0)
                        {
                            sFile = file.GetName();
                            file.SaveAs(sPath.ToString() + file.GetName());
                        }
                    }
                    cAppLogoCliente oAppLogoCliente = new cAppLogoCliente(ref oConn);
                    oAppLogoCliente.NKey_cliente = CodCliente.Value;
                    oAppLogoCliente.LogoCliente  = sFile;
                    oAppLogoCliente.Tipo         = (string.IsNullOrEmpty(hddTipo.Value) ? "C" : hddTipo.Value);
                    oAppLogoCliente.Accion       = (string.IsNullOrEmpty(hddAccion.Value) ? "CREAR" : "EDITAR");
                    oAppLogoCliente.Put();

                    getImage(sFile);
                }
                oConn.Close();
            }
            catch (Exception Ex)
            {
                Response.Write("Error: " + Ex.Message);
            }
        }
        protected void btnCargar_Click(object sender, EventArgs e)
        {
            // RadAjaxManager1.ResponseScripts.Add(String.Format("radconfirm('¿Desea continuar?', confirmCallBackFn, 330, 100, null,'Importación', '');"));
            string path = path = this.MapPath("/");

            //string curTempFileName = Path.GetTempFileName();
            //FileInfo f = new FileInfo(curTempFileName);

            //file = new FileInfo(FileUpload1.FileName);
            //if (RadUpload2.InvalidFiles.Count > 0)
            //{
            //    Label2.Visible = true;
            //}
            if (RadUpload2.UploadedFiles.Count > 0)
            {
                Label2.Visible = false;
                UploadedFile f    = RadUpload2.UploadedFiles[0];
                string       name = f.GetName();
                string       p    = String.Format("{0}.sdf", Path.GetTempFileName());
                //string name = String.Format(@"{0}.sdf", Guid.NewGuid());
                //string filepath = string.Format("{0}BDII\\{1}", path, name);
                lblPath.Text = p;
                //if(File.Exists(filepath))
                //   filepath = String.Format(@"{0}.sdf", Guid.NewGuid());
                f.SaveAs(p);

                file = new System.IO.FileInfo(p);

                AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
                SqlCeConnection conn = GetConnection();

                if (GetEmpresa(conn))
                {
                    PantallaValidacion(conn);
                }
                else
                {
                    RadNotification1.Text = String.Format("<b>{0}</b><br/>{1}",
                                                          (string)GetGlobalResourceObject("ResourceLainsaSci", "Warning"),
                                                          (string)GetGlobalResourceObject("ResourceLainsaSci", "ImportEmpresa"));
                    RadNotification1.Show();
                    return;
                }
            }
        }
Exemple #13
0
    protected void btnLoader_Click(object sender, EventArgs e)
    {
        //
        //if (rdUploader.InvalidFiles.Count > 0)
        //{
        //    RadWindowManager1.RadAlert(String.Format("Debe escoger un fichero con la extensión {0}",extension), null, null, "Aviso", "doNothing");
        //    return;
        //}
        // when file have been loaded this event fires
        int nf = rdUploader.UploadedFiles.Count;

        if (nf == 0)
        {
            RadWindowManager1.RadAlert("Debe escoger un fichero", null, null, "Aviso", "doNothing");
            return;
        }
        UploadedFile f    = rdUploader.UploadedFiles[0];
        string       name = f.GetName();
    }
    private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file)
    {
        const int total = 100;

        RadProgressContext progress = RadProgressContext.Current;

        for (int i = 0; i < total; i++)
        {
            progress["SecondaryTotal"] = total.ToString();
            progress["SecondaryValue"] = i.ToString();
            progress["SecondaryPercent"] = i.ToString();
            progress["CurrentOperationText"] = file.GetName() + " is being processed...";

            if (!Response.IsClientConnected)
            {
                //Cancel button was clicked or the browser was closed, so stop processing
                break;
            }

            //Stall the current thread for 0.1 seconds
            System.Threading.Thread.Sleep(100);
        }
    }
Exemple #15
0
    private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file)
    {
        const int total = 100;

        RadProgressContext progress = RadProgressContext.Current;

        for (int i = 0; i < total; i++)
        {
            progress["SecondaryTotal"]       = total.ToString();
            progress["SecondaryValue"]       = i.ToString();
            progress["SecondaryPercent"]     = i.ToString();
            progress["CurrentOperationText"] = file.GetName() + " is being processed...";

            if (!Response.IsClientConnected)
            {
                //Cancel button was clicked or the browser was closed, so stop processing
                break;
            }

            //Stall the current thread for 0.1 seconds
            System.Threading.Thread.Sleep(100);
        }
    }
Exemple #16
0
 public void Push(UploadedFile file)
 {
     Package.AddStream(file.InputStream, file.GetName());
 }
Exemple #17
0
    protected void btnUploadMDB_onclick(object sender, EventArgs e)
    {
        //UploadedFile file = RadUploadContext.Current.UploadedFiles[inputFile1.UniqueID];
        DataTable  dtTable = new DataTable();
        DataColumn dcCol   = new DataColumn("FileName", Type.GetType("System.String"));

        dtTable.Columns.Add(dcCol);

        dcCol = new DataColumn("ContentLength", Type.GetType("System.String"));
        dtTable.Columns.Add(dcCol);
        dtTable.AcceptChanges();

        txtHFileName.Value = "";
        for (int Xh = 1; Xh <= RadUploadContext.Current.UploadedFiles.Count; Xh++)
        {
            HtmlInputFile inputFile = (HtmlInputFile)(FindControl("inputFile" + Xh));
            UploadedFile  file      = RadUploadContext.Current.UploadedFiles[inputFile.UniqueID];

            if (file != null)
            {
                const int total = 100;

                RadProgressContext progress = RadProgressContext.Current;
                for (int i = 0; i < total; i++)
                {
                    progress["SecondaryTotal"]       = total.ToString();
                    progress["SecondaryValue"]       = i.ToString();
                    progress["SecondaryPercent"]     = i.ToString();
                    progress["CurrentOperationText"] = file.GetName() + " is being processed...";

                    if (!Response.IsClientConnected)
                    {
                        //Cancel button was clicked or the browser was closed, so stop processing
                        break;
                    }

                    //Stall the current thread for 0.1 seconds
                    System.Threading.Thread.Sleep(100);
                }

                string strMDBPath = Server.MapPath(".") + "/MDB/" + Request.Cookies["UserPracticeCode"].Value + file.GetName();
                try { System.IO.File.Delete(strMDBPath); }
                catch { }
                try
                {
                    DataRow drRow = dtTable.NewRow();
                    drRow["FileName"]      = file.GetName();
                    drRow["ContentLength"] = file.ContentLength.ToString();
                    dtTable.Rows.Add(drRow);
                    dtTable.AcceptChanges();

                    file.SaveAs(strMDBPath);
                    div_importStep1A.Style["display"] = "none";
                    div_importStep1B.Style["display"] = "none";
                    div_importStep2A.Style["display"] = "block";
                    txtHFileName.Value += file.GetName() + ";";
                }
                catch (Exception err) { Response.Write(err.ToString()); }
            }
        }

        repeaterUpload.DataSource = dtTable.DefaultView;
        repeaterUpload.DataBind();
        return;
    }
Exemple #18
0
    protected void  нопка_OK_Click(object sender, EventArgs e)
    {
        try
        {
            »мпортерƒанныхќтчетных‘орм импортер = ѕолучить»мпортер();

            if (импортер != null && RadUpload_файл.UploadedFiles.Count > 0)
            {
                UploadedFile file = RadUpload_файл.UploadedFiles[0];

                string ѕуть ‘айлу = string.Format("{0}/{1}", RadUpload_файл.TargetFolder, file.GetName());

                ѕуть ‘айлу = HttpContext.Current.Server.MapPath(ѕуть ‘айлу);

                импортер.»м¤‘айла = ѕуть ‘айлу;

                bool результат = импортер.»мпортировать();

                if (!результат)
                {
                    throw new Exception("ќшибка импорта!");
                }
            }

            this.Controls.Add(new LiteralControl("<script type='text/javascript'>CloseAndRebindSheets();</script>"));
        }
        catch (Exception exc)
        {
            string “екстќшибки = exc.Message;
            “екстќшибки = “екстќшибки.Replace("\"", "'");
            “екстќшибки = “екстќшибки.Replace("\n", "");
            “екстќшибки = “екстќшибки.Replace("\r", "");
            “екстќшибки = “екстќшибки.Replace("'", "");

            this.Controls.Add(new LiteralControl(string.Format("<script type=\"text/javascript\">alert('¬о врем¤ выполнени¤ импорта произошла ошибка! {0}');</script>", “екстќшибки)));
        }
    }
        protected void UpdatePhoto(object sender, EventArgs e)
        {
            if (ruUserImage.UploadedFiles.Count > 0)
            {
                newFile = ruUserImage.UploadedFiles[0];
                /* is the file name of the uploaded file 50 characters or less?  
                    * The database field that holds the file name is 50 chars.
                    * */
                if (newFile.ContentLength > AppSettings.ProfileImageMaxFileSize)
                {
                    lblUpdateResults.Text = "The file being imported is too big. Please select another file.";
                }
                else
                {
                    if (newFile.GetName().Length <= AppSettings.ProfileImageMaxFileNameLength)
                    {
                        var uploadFolder = Server.MapPath(AppSettings.ProfileImageUserWebPath);

                        string newFileName;

                        do
                        {
                            newFileName = (Path.GetRandomFileName()).Replace(".", "") +
                                          newFile.GetExtension();
                        } while (System.IO.File.Exists(Path.Combine(uploadFolder, newFileName)));

                        try
                        {
                            newFile.SaveAs(Path.Combine(uploadFolder, newFileName));

                            var oUser = SessionObject.LoggedInUser;
                            var successful = oUser.UpdateUserImageFilename(newFileName);
                            if (successful)
                            {
                                //attempt to delete the old file
                                if (imgPhoto.Src != "/Images/person.png")
                                {
                                    var oldFilePath = Server.MapPath(imgPhoto.Src);
                                    File.Delete(oldFilePath);
                                }
                                oUser.ImageFilename = newFileName;
                                SessionObject.LoggedInUser = oUser;

                                imgPhoto.Src = AppSettings.ProfileImageUserWebPath + "/" + newFileName;
                            }
                            else
                            {
                                lblUpdateResults.Text = "Database error. Please contact system administrator.";
                            }
                        }
                        catch (Exception ex)
                        {
                            lblUpdateResults.Text = "Image Import unsuccessful. Please contact system adminstrator.";
                        }
                    }
                    else
                    {
                        lblUpdateResults.Text = "Image filename length must be 50 characters or less. Please rename the file and try again.";
                    }
                }
            }
            else
            {
                lblUpdateResults.Text = "Image import unsuccessful. No image specified.";
            }
        }
 public void Push(UploadedFile file)
 {
     Package.AddStream(file.InputStream, file.GetName());
 }
Exemple #21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int code_ostad = Convert.ToInt32(Session[sessionNames.userID_StudentOstad]);
                if (ProfReqBuss.HasPendingRequest(code_ostad, (int)RequestTypeId.EditHokm))
                {
                    ShowView = false;
                    string msg = "شما به دلیل وجود درخواست تایید نشده از این نوع درخواست نمی توانید درخواست جدید ثبت کنید.";
                    RadWindowManager2.RadAlert(msg, 500, 100, "پیام سیستم", "RedirectToMain");
                    return;
                }
                LoadInfoToForm();
            }
            if (flpHokm.UploadedFiles.Count > 0)
            {
                UploadedFile obj = flpHokm.UploadedFiles[0];
                string       ScanMadarekURL;
                if (!Directory.Exists(Server.MapPath("~/University/CooperationRequest/Teachers/ScanMadarek/")))
                {
                    Directory.CreateDirectory(Server.MapPath("~/University/CooperationRequest/Teachers/ScanMadarek/"));
                }
                string subPath = Server.MapPath("~/University/CooperationRequest/Teachers/ScanMadarek/") + Session[sessionNames.userID_StudentOstad].ToString() + "\\";

                bool exists = System.IO.Directory.Exists(subPath);

                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(subPath);
                }
                try
                {
                    ScanMadarekURL = subPath + "Hokm" + DateTime.Now.ToPeString("yyyy-MM-dd_HH-mm-ss") + obj.GetName();
                    obj.SaveAs(ScanMadarekURL.improveFileName(), true);
                }
                catch (Exception)
                {
                    throw;
                }
                Session.Add("ScanMadarekURL", ScanMadarekURL);
            }
        }
Exemple #22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadInfoToForm();
            }
            if (flpHokm.UploadedFiles.Count > 0)
            {
                UploadedFile obj = flpHokm.UploadedFiles[0];
                string       ScanMadarekURL;
                if (!Directory.Exists(Server.MapPath("~/University/CooperationRequest/Teachers/ScanMadarek/")))
                {
                    Directory.CreateDirectory(Server.MapPath("~/University/CooperationRequest/Teachers/ScanMadarek/"));
                }
                string subPath = Server.MapPath("~/University/CooperationRequest/Teachers/ScanMadarek/") + Session[sessionNames.userID_StudentOstad].ToString() + "\\";

                bool exists = System.IO.Directory.Exists(subPath);

                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(subPath);
                }
                try
                {
                    ScanMadarekURL = subPath + "Hokm" + DateTime.Now.ToPeString("yyyy-MM-dd_HH-mm-ss") + obj.GetName();
                    obj.SaveAs(ScanMadarekURL.improveFileName(), true);
                }
                catch (Exception)
                {
                    throw;
                }
                Session.Add("ScanMadarekURL", ScanMadarekURL);
            }
        }
Exemple #23
0
        protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            var fileUpload = (RadAsyncUpload)sender;

            if (fileUpload.UploadedFiles.Count > 0)
            {
                UploadedFile file = fileUpload.UploadedFiles[0];
                SessionInfo.CurrentResourceLink.ThumbNail = "/images/thumbnails/{0}".FormatWith(file.GetName());
                file.SaveAs("{0}/{1}".FormatWith(Server.MapPath("~/images/thumbnails"), file.GetName()), true);
            }
        }