public static ArrayList MergrObj(string strPath) { IList <DirectoryInfo> dir = GetDirectorys(strPath); IList <FileInfo> fi = GetFiles(strPath); ArrayList al = new ArrayList(); foreach (DirectoryInfo d in dir) { if (d.Attributes.HasFlag(FileAttributes.System) || d.Attributes.HasFlag(FileAttributes.Hidden)) { ; } else { string fullname = d.Name;// JsonOper.ReturnSplitBrString(d.Name); string name = JsonOper.GetString(d.Name, 6, ".."); string filetype = d.Attributes.ToString(); string size = Disk.GetFileLength(d.FullName); string lastTime = d.LastWriteTime.ToString("yyyy-MM-dd HH:mm"); al.Add("0|" + name + "|" + fullname + "|文件夹|" + size + "|" + lastTime); } } foreach (FileInfo f in fi) { string fullname = f.Name; //JsonOper.ReturnSplitBrString(f.Name); string name = JsonOper.GetString(f.Name, 6, ".."); string filetype = f.Attributes.ToString(); string size = f.Length + ""; string lastTime = f.LastWriteTime.ToString("yyyy-MM-dd HH:mm"); string extName = fullname.Substring(fullname.LastIndexOf(".") + 1, (fullname.Length - fullname.LastIndexOf(".") - 1)); al.Add("1|" + name + "|" + fullname + "|" + FileType(extName) + "|" + size + "|" + lastTime); } return(al); }
private void button3_Click(object sender, EventArgs e) { string path = ""; string fname = ""; string extname = ""; string ftype = ""; string dir = ""; OpenFileDialog op = new OpenFileDialog(); op.Title = "请选择教学资源文件"; //op.Filter = "All Files(*.*)|*.*|ppt Files(*.ppt)|*.ppt|word 2007 Files(*.doc)|*.doc|excel 2007 Files(*.xls)|*.xls|word Files(*.docx)|*.docx|excel Files(*.xlsx)|*.xlsx"; op.Filter = "课件文件(*.ppt,*.pptx,*.doc,*.docx,*.jpg,*.jpeg,*.bmp,*.png,*.gif,*.mp3,*.mp4,*.wav,*.wma,*.wmv,*.mov,*.swf)|*.ppt;*.pptx;*.doc;*.docx;*.jpg;*.jpeg;*.bmp;*.png;*.gif;*.mp3;*.wav;*.wma;*.mp4;*.wmv;*.mov;*.swf"; //op.Filter = "课件文件(*.ppt,*.pptx,*.doc,*.docx,*.pdf,*.jpg,*.jpeg,*.bmp,*.png,*.gif,*.mp3,*.mp4,*.wav,*.wma,*.wmv,*.mov,*.swf)|*.ppt;*.pptx;*.doc;*.docx;*.pdf;*.jpg;*.jpeg;*.bmp;*.png;*.gif;*.mp3;*.wav;*.wma;*.mp4;*.wmv;*.mov;*.swf"; if (op.ShowDialog() == DialogResult.OK) { path = op.FileName; dir = path.Substring(0, path.LastIndexOf("\\")); fname = op.SafeFileName; extname = fname.Substring(fname.LastIndexOf(".") + 1, (fname.Length - fname.LastIndexOf(".") - 1));; } if (path != "") { Button btn = new Button(); btn.Size = new System.Drawing.Size(70, 70); btn.BackColor = System.Drawing.Color.FromArgb(255, 255, 255); btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(153, 209, 255); btn.FlatAppearance.BorderSize = 0; btn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(204, 232, 255); btn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(229, 243, 255); btn.TextAlign = ContentAlignment.BottomCenter; btn.MouseMove += new System.Windows.Forms.MouseEventHandler(btn_MouseMove); btn.MouseDown += new System.Windows.Forms.MouseEventHandler(btn_MouseDown); btn.AllowDrop = true; string filename = fname; string extName = extname; btn.BackgroundImage = FileICON(extName); btn.Name = "1|" + dir + "|" + fname; btn.Text = JsonOper.GetString(fname, 6, ".."); FileInfo fileInfo = new System.IO.FileInfo(path); string tooltipStr = fname + "\r\n类型:" + Disk.FileType(extName) + "\r\n修改日期:" + fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm") + "\r\n大小:" + fileInfo.Length + "字节"; this.toolTip1.SetToolTip(btn, tooltipStr); btn.MouseDown -= new System.Windows.Forms.MouseEventHandler(btn_MouseDown); btn.MouseDown += new System.Windows.Forms.MouseEventHandler(btnRight_MouseDown); addButtonlist_Right(btn); //添加本地文件 RefreshControls(); //button3_Click sourcePath = btn.Name.Split('|')[1].ToString(); sourceFilename = btn.Name.Split('|')[2].ToString(); System.Threading.Thread thred = new System.Threading.Thread(AsnycCopy);//拖动 thred.Start(); } }
/// <summary> /// 刷新控件 /// </summary> public void AddFile(string filepath, bool bCopy) { string fname = Path.GetFileName(filepath); string extName = Path.GetExtension(filepath).Substring(1); string dir = Path.GetDirectoryName(filepath); Button btn = new Button(); btn.Size = new System.Drawing.Size(70, 70); btn.BackColor = System.Drawing.Color.FromArgb(255, 255, 255); btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(153, 209, 255); btn.FlatAppearance.BorderSize = 0; btn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(204, 232, 255); btn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(229, 243, 255); btn.TextAlign = ContentAlignment.BottomCenter; btn.MouseMove += new System.Windows.Forms.MouseEventHandler(btn_MouseMove); btn.MouseDown += new System.Windows.Forms.MouseEventHandler(btn_MouseDown); btn.AllowDrop = true; btn.BackgroundImage = FileICON(extName); btn.Name = "1|" + dir + "|" + fname; btn.Text = JsonOper.GetString(fname, 6, ".."); FileInfo fileInfo = new System.IO.FileInfo(filepath); string tooltipStr = fname + "\r\n类型:" + Disk.FileType(extName) + "\r\n修改日期:" + fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm") + "\r\n大小:" + fileInfo.Length + "字节"; this.toolTip1.SetToolTip(btn, tooltipStr); btn.MouseDown -= new System.Windows.Forms.MouseEventHandler(btn_MouseDown); btn.MouseDown += new System.Windows.Forms.MouseEventHandler(btnRight_MouseDown); addButtonlist_Right(btn);//添加本地文件 RefreshControls(); sourcePath = btn.Name.Split('|')[1].ToString(); sourceFilename = btn.Name.Split('|')[2].ToString(); if (bCopy) { System.Threading.Thread thred = new System.Threading.Thread(AsnycCopy);//拖动 thred.Start(); } }
public static ArrayList getFilelist(string strPath, string[] szType) { IList <FileInfo> fi = GetFiles(strPath); ArrayList al = new ArrayList(); foreach (FileInfo f in fi) { string fullname = f.Name; string name = JsonOper.GetString(f.Name, 6, ".."); string filetype = f.Attributes.ToString(); string size = f.Length + ""; string lastTime = f.LastWriteTime.ToString("yyyy-MM-dd HH:mm"); string extName = fullname.Substring(fullname.LastIndexOf(".") + 1, (fullname.Length - fullname.LastIndexOf(".") - 1)); foreach (string type in szType) { if (fullname.IndexOf("." + type) > 0) { al.Add("1|" + name + "|" + fullname + "|" + FileType(extName) + "|" + size + "|" + lastTime); break; } } } return(al); }