About. NET file drag and drop issues

Source: Internet
Author: User

Today you need to do a function, is the customer directly drag the file to the WinForm interface, and then display the file content.

In fact, this function point is to get the path of the dragged file.

It is generally necessary to set up three places:

1. The AllowDrop property of the control that accepts the file is set to True.

2. The control that accepts the file plus the DragDrop event.

This.dgv_openJsonFile1.Cursor = System.Windows.Forms.Cursors.Default;            if (!e.data.getdatapresent (DataFormats.FileDrop)) {                return;            }            var path = e.Data.GetData (DataFormats.FileDrop) as string[];            if (path! = null && path. Length > 0) {                var jsonPath = path[0];                if (!string. IsNullOrEmpty (JsonPath)) {                  //Todo:jsonpath and file path ...                }            }


3. The control that accepts the file plus the DragEnter event.

if (E.data.getdatapresent (DataFormats.FileDrop)) {                e.effect = Dragdropeffects.link;                This.dgv_openJsonFile1.Cursor = System.Windows.Forms.Cursors.Arrow;            } else {                e.effect = DragDropEffects.None;            }


Only three of the above can be

But I've been doing it for a long time.

Know the last to know, originally because of the permissions problem:

Drag-and-drop messages cannot be shared between programs that have different privilege elevation levels. You can do a simple experiment. Run Notepad with the administrator and drag the TXT file from Windows Explorer to find that the file does not open at all. Because Windows Explorer has a privilege elevation level of invokeasuser, not requireadministrator. The same level of privileges to elevate the account running program can be Share drag and drop. If the resources of the system are not involved, such as dragging files. Dragging within your own program is independent of the level of UAC.


My reason is because I ran the VS as an administrator. Remove run as administrator, and normal.



About. NET file drag and drop issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.