Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Dragging a file into a RichTextBox - want only the path to the file, not the file iteself

$
0
0

Hi.

I have a rich text box that I want to allow drag and drop from Windows Explorer, and that part works.  Sort of.  When I drag a file into the text box I get two bits of info - one is the actual file itself represented by an icon, and the other is the path to the file.

I only want the path to remain in the rich text box.

But every time I drag and drop a file, I see both things - the file (as a icon) and the path to the file. The code I'm using now is:

private void txtName_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true) { string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false); string s = ""; foreach (string File in FileList) { s = s + " " + File; } txtName.Text = s; } }

I tried several workarounds to get rid of the file - including trying to use txtName.Clear() to remove everything and then assign the path to txtName.Text but no matte what I do, I always end up with the icon that represents the file I dragged and dropped.

Even when I only drag a single file into the RichTextBox, the 'File' in the foreach loop only ever has a single index - zero, and when I look at this in the debugger I only ever see the full path to the file.  So I cannot parse this as it has only a single value.

I even tried just a regular textbox but I always see the circle with a line through it preventing me from dropping anything onto the control, even with AllowDrop set to true.

Any help you can provide would be greatly appreciated.

Thanks.

Logan




Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>