Ejemplo n.º 1
0
 protected void getDirec()
 {
     try
     {
         string path = Server.MapPath(@"Portals\0\");
         string[] direc = Directory.GetDirectories(path);
         DataTable dt = new DataTable();
         DataColumn dc = new DataColumn("FolderPath");
         dt.Columns.Add(dc);
         dc = new DataColumn("FolderName");
         dt.Columns.Add(dc);
         news_class ob = new news_class();
         foreach (string s in direc)
         {
             DataRow dr = dt.NewRow();
             dr["FolderPath"] = s;
             dr["FolderName"] = ob.pathFromPortals(s);
             dt.Rows.Add(dr);
         }
         ddThuMuc.DataSource = dt;
         ddThuMuc.DataBind();
     }
     catch (Exception ex) { lbError.Text = ex.Message; }
 }
Ejemplo n.º 2
0
 protected void upload()
 {
     if (fileUpload.HasFile)
     {
         //if (fileUpload.PostedFile.ContentLength > 1048576)                             
         string ext = Path.GetExtension(fileUpload.FileName).ToLower();
         if (ext == ".jpeg" || ext == ".jpg" || ext == ".gif" || ext == ".png")
         {
             try
             {
                 string my_folder = Server.MapPath(@"Portals\0\") + DateTime.Today.ToString("yyyy-MM") + "\\";
                 if (!Directory.Exists(my_folder)) Directory.CreateDirectory(my_folder);
                 news_class ob = new news_class();
                 string my_filename = ob.rewriteFilename(fileUpload.FileName);
                 fileUpload.SaveAs(my_folder + my_filename);
                 tbHinhAnh.Text = ob.webPath(ob.pathFromPortals(my_folder) + my_filename);
                 imgHinhAnh.ImageUrl = ob.webPath(ob.pathFromPortals(my_folder) + my_filename);
                 getDirec();
             }
             catch (Exception ex) { lbError.Text = ex.Message; }
         }
         else lbError.Text = "Chỉ chấp nhận các định dạng jpeg, jpg, gif, png.";
     }
     else lbError.Text = "Chưa chọn file đính kèm";
 }
Ejemplo n.º 3
0
 protected void btXem_Click(object sender, EventArgs e)
 {
     try
     {
         string[] files = Directory.GetFiles(ddThuMuc.SelectedValue);
         DataTable dt = new DataTable();
         DataColumn dc = new DataColumn("FilePath");
         dt.Columns.Add(dc);
         dc = new DataColumn("FileName");
         dt.Columns.Add(dc);
         news_class ob = new news_class();
         foreach (string s in files)
         {
             string ext = Path.GetExtension(s).ToLower();
             if (ext == ".jpeg" || ext == ".jpg" || ext == ".gif" || ext == ".png")
             {
                 DataRow dr = dt.NewRow();
                 dr["FilePath"] = ob.webPath(ob.pathFromPortals(s));
                 dr["FileName"] = Path.GetFileNameWithoutExtension(s);
                 dt.Rows.Add(dr);
             }
         }
         dlHinhAnh.DataSource = dt;
         dlHinhAnh.DataBind();
     }
     catch (Exception ex) { lbError.Text = ex.Message; }
 }