Beispiel #1
0
 public static bool Delete(String[] source, IntPtr handle)
 {
     ShellFileOperation fo = new ShellFileOperation();
     fo.Operation = ShellFileOperation.FileOperations.FO_DELETE;
     fo.OwnerWindow = handle;
     fo.SourceFiles = source;
     bool RetVal = fo.DoOperation();
     return RetVal;
 }
Beispiel #2
0
 public static bool Copy(String[] source, String[] dest, IntPtr handle)
 {
     ShellFileOperation fo = new ShellFileOperation();
     fo.Operation = ShellFileOperation.FileOperations.FO_COPY;
     fo.OwnerWindow = handle;
     fo.SourceFiles = source;
     fo.DestFiles = dest;
     bool RetVal = fo.DoOperation();
     return RetVal;
 }
        private void 添加_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Multiselect = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ShellFileOperation fo = new ShellFileOperation();
                String[] source = openFileDialog1.FileNames;
                String[] dest = new String[openFileDialog1.FileNames.Length];

                for(int i=0;i<openFileDialog1.FileNames.Length;i++)
                     dest[i] = FileCore.NewName(workpath + "\\" + Path.GetFileName(openFileDialog1.FileNames[i]));

                fo.Operation = FileOperations.FO_COPY;
                fo.OwnerWindow = this.Handle;
                fo.SourceFiles = source;
                fo.DestFiles = dest;

                if (!fo.DoOperation())
                    MessageBox.Show("添加文件过程中出错!", "附件",  MessageBoxButtons.OK,MessageBoxIcon.Error);

                LoadData(workpath);
            }
        }
        private void 删除_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection SelectedItem = new ListView.SelectedListViewItemCollection(listView1);
            DialogResult d = MessageBox.Show("删除选中的 " + SelectedItem.Count + " 项?", "附件", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            String[] source = new string[SelectedItem.Count];
            ShellFileOperation fo = new ShellFileOperation();
            fo.Operation = FileOperations.FO_DELETE;
            fo.OwnerWindow = this.Handle;
            fo.SourceFiles = source;

            if (d == DialogResult.Yes)
            {
                for (int i = 0; i < SelectedItem.Count; i++)
                    source[i] = workpath + "\\" + SelectedItem[i].Text;

                if (!fo.DoOperation())
                    MessageBox.Show("删除文件过程中出错!", "附件", MessageBoxButtons.OK, MessageBoxIcon.Error);

                for (int i = 0; i < SelectedItem.Count; )
                    listView1.Items.Remove(SelectedItem[i]);

                LoadData(workpath);
            }
        }
        protected override void WndProc(ref Message Msg)
        {
            if (Msg.Msg == 0x0233)// WM_DROPFILES
            {
                uint FilesCount = Win32API.DragQueryFile((int)Msg.WParam, 0xFFFFFFFF, null, 0);

                StringBuilder FileName = new StringBuilder(1024);

                ShellFileOperation fo = new ShellFileOperation();
                String[] source = new String[FilesCount];
                String[] dest = new String[FilesCount];
                for (uint i = 0; i < FilesCount; i++)
                {
                    Win32API.DragQueryFile((int)Msg.WParam, i, FileName, 1024);
                    source[i] = FileName.ToString();
                    dest[i] = FileCore.NewName(workpath + "\\" + Path.GetFileName(FileName.ToString()));
                }
                Win32API.DragFinish((int)Msg.WParam);

                fo.Operation = FileOperations.FO_COPY;
                fo.OwnerWindow = this.Handle;
                fo.SourceFiles = source;
                fo.DestFiles = dest;

                if (!fo.DoOperation())
                    MessageBox.Show("添加文件过程中出错!", "附件", MessageBoxButtons.OK, MessageBoxIcon.Error);

                LoadData(workpath);

                return;
            }
            base.WndProc(ref Msg);
        }