Inheritance: ScriptControlBase
示例#1
0
        public static string SaveUploadeFile(AsyncFileUpload fup, string SaveFolder, UploadFileType filetype, UploadFileSizeLimitation filesizelimit, UploadImageSize? Imagesize = null)
        {

            string FileExtension = Path.GetExtension(fup.FileName);

            if (!IsValidFileType(FileExtension, filetype))
            {
                MessageBoxHelper.ShowMessageBox(fup.Page, "نوع فایل نامعتبر است", "", MessageBoxType.Information);
                return null;
            }
            if (!IsValidFileSize(fup.FileBytes.Length.ToLong(), filesizelimit))
            {
                MessageBoxHelper.ShowMessageBox(fup.Page, "حجم فایل نامعتبر است", "", MessageBoxType.Information);
                return null;
            }

            MemoryStream memStream = Imagesize.HasValue ? ResizeImage(fup.FileBytes, Imagesize.Value, FileExtension) : new MemoryStream(fup.FileBytes);


            string FileName = Path.GetFileNameWithoutExtension(fup.FileName);
            if (FileName != null) FileName = FileName.Replace(" ", "_");

            FileName = FileName + "__" + Common.CreateTemporaryPassword(8) + FileExtension;
            String AttchFilePath = HttpContext.Current.Server.MapPath(SaveFolder + FileName);
            File.WriteAllBytes(AttchFilePath, memStream.ToArray());
            return FileName;

        }
示例#2
0
        public static Guid UploadAttach(AsyncFileUpload fu)
        {
            if (!fu.HasFile || fu.FileName.Length == 0)
            {
                throw new BusinessObjectLogicException("Please select upload file!");
            }

            string path = null;
            try
            {
                string subDirectory = DateTime.Now.ToString("yyyyMM") + Path.DirectorySeparatorChar + DateTime.Now.ToString("dd");
                string directory = System.Configuration.ConfigurationManager.AppSettings["File"] + subDirectory;

                if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);

                string title = Path.GetFileName(fu.FileName);
                string ext = Path.GetExtension(fu.FileName);

                path = Path.DirectorySeparatorChar + Path.GetRandomFileName() + ext;

                fu.SaveAs(directory + path);

                Attachment attach = new Attachment(UserHelper.UserName);
                attach.Title = title;
                attach.Path = subDirectory + path;

                new AttachmentBl().AddAttach(attach);

                return attach.UID;
            }
            catch
            {
                throw new BusinessObjectLogicException("File upload fail!");
            }
        }
示例#3
0
    protected void ULComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        AjaxControlToolkit.AsyncFileUpload fileupload = (AjaxControlToolkit.AsyncFileUpload)sender;
        //Upload files
        if (fileupload.HasFile)
        {
            //use newly created id to name file
            string newfilename = Path.GetFileNameWithoutExtension(fileupload.FileName);
            string savepath    = Server.MapPath("~/admin/xml/");
            string extension   = Path.GetExtension(fileupload.FileName);

            string newfile = shared.SaveFile(fileupload.PostedFile, newfilename, savepath, extension);
            LoadXML(newfile);
        }
    }
示例#4
0
    protected void ULComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        //System.Diagnostics.Debug.Write("Upload Complete");

        LabelStatus.Text += "UL Completed<br/>";

        AjaxControlToolkit.AsyncFileUpload fileupload = (AjaxControlToolkit.AsyncFileUpload)sender;
        //Upload files
        if (fileupload.HasFile)
        {
            //use newly created id to name file
            string newfilename = Path.GetFileNameWithoutExtension(fileupload.FileName);
            string savepath    = Server.MapPath("~/admin/xml/");
            string extension   = Path.GetExtension(fileupload.FileName);
            string newfile     = shared.SaveFile(fileupload.PostedFile, newfilename, savepath, extension);
            LoadXML(newfile);
        }
        else
        {
            LabelStatus.Text = "No valid file uploaded.";
        }
    }
示例#5
0
文件: Uploader.cs 项目: t1b1c/lwas
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            filePathHidden = new HiddenField();
            filePathHidden.ID = "filePathHidden";
            this.Controls.Add(filePathHidden);

            this.uploader = new AsyncFileUpload();
            this.uploader.ID = "uploader";
            this.uploader.CssClass = "uploader";
            this.Controls.Add(this.uploader);
            if (this.Width == default(Unit))
                this.Width = Unit.Pixel(250);
            this.uploader.Width = Unit.Pixel((int)this.Width.Value - 5);
            this.uploader.UploadedComplete += new EventHandler<AsyncFileUploadEventArgs>(this.uploader_UploadedComplete);

            hiddenCommand = new Button();
            hiddenCommand.ID = "hiddenCommand";
            hiddenCommand.CommandName = "view";
            hiddenCommand.Style.Add(HtmlTextWriterStyle.Display, "none");
            this.Controls.Add(hiddenCommand);
        }
示例#6
0
 public static string SaveImageAsync(AsyncFileUpload Fu, string prefix, string localImagePath)
 {
     if (!Directory.Exists(localImagePath))
         Directory.CreateDirectory(localImagePath);
     string strImage = string.Empty;
     string SavePath = string.Empty;
     //SavePath = GetImagePathWithFileName(3, prefix, localImagePath);
     SavePath = localImagePath;
     SavePath += '\\' + prefix;
     Fu.SaveAs(SavePath);
     Fu.FileContent.Dispose();
     strImage = SavePath;
     //Fu.PostedFile.ContentLength
     return strImage;
 }
示例#7
0
    protected void ULComplete_CSV_Exotics(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        LabelStatus.Text += "UL Completed<br/>";

        AjaxControlToolkit.AsyncFileUpload fileupload = (AjaxControlToolkit.AsyncFileUpload)sender;
        //Upload files
        if (fileupload.HasFile)
        {
            //use newly created id to name file
            string newfilename = "exotics";
            string savepath    = Server.MapPath("~/admin/csv/");
            string extension   = Path.GetExtension(fileupload.FileName);
            LabelStatus.Text += "Saving File:<br/>";
            string newfile = shared.SaveFile(fileupload.PostedFile, newfilename, savepath, extension);
            LabelStatus.Text += "Loading Exotics Information:<br/>";
            string csvfile = newfile;

            string path = Server.MapPath("~/admin/csv/" + csvfile);
            string full = Path.GetFullPath(path);
            string file = Path.GetFileName(full);
            string dir  = Path.GetDirectoryName(full);

            //create the "database" connection string
            //Microsoft.ACE.OLEDB.12.0
            string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
                                + "Data Source=\"" + dir + "\\\";"
                                + "Extended Properties=\"text;HDR=No;FMT=Delimited\"";
            //LabelStatus.Text += "<br/>";
            //LabelStatus.Text+= connString + "<br/>";
            //LabelStatus.Text += "<br/>File Location: " + dir + "\\" + file;
            //LabelStatus.Text += "<br/>Exists: " + System.IO.File.Exists(dir + "\\" + file) + "<br/>" + System.IO.File.ReadAllText(dir + "\\" + file) + "<br/><br/>";
            //create the database query
            string query = "SELECT * FROM " + csvfile;
            //create a DataTable to hold the query results
            DataTable dTable = new DataTable();
            //create an OleDbDataAdapter to execute the query
            OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
            try
            {
                //fill the DataTable
                dAdapter.Fill(dTable);
            }
            catch (InvalidOperationException /*e*/)
            { }


            dAdapter.Dispose();

            LabelStatus.Text += "Loading Inormation";
            try
            {
                //LoadInfo(dTable);
                ProcessCSV_Exotics(dTable);
            }
            catch (Exception ex) { LabelStatus.Text = "Error Loading csv: " + ex.ToString(); }
        }
        else
        {
            LabelStatus.Text = "No valid file uploaded.";
        }
    }