Thursday, March 22, 2012

Windows Control hosted in WebForm

I need to be able to allow users to drag files to a list box on a web
page. To this end, I created a Windows Control and hosted it in a
WebForm. When the file is dropped onto the listbox, the path of the
file is truncated down to 8.3 format (with the ~1 at the end). When the
Windows control is hosted in a windows form (for testing purposes) the
full path is displayed.

Is there some setting that will allow the full path to be displayed when
hosted in a WebForm?

Alternatively, is there a different way to achieve the desired
functionality without using a WinForm control?

And less importantly, when hosted in an WebForm, the control is only
able to accept 1 file at a time. When hosted in a WinForm, the control
can accept multiple files. Any ideas?

Thanks

private void listBox1_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.All;
else
e.Effect = DragDropEffects.None;
}

private void listBox1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
try
{
string[] files = null;
if (e.Data.GetDataPresent(System.Windows.Forms.DataFo rmats.FileDrop))
{
files = (string[])e.Data.GetData("FileDrop", true);
}

foreach (string s in files)
{
listBox1.Items.Add(s);
}
}
catch (Exception exp)
{
System.Windows.Forms.MessageBox.Show(exp.Message);
}
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Perhaps you could use the GetLongPathName API call in your windows control
to convert the 8.3 format.
Here's more information:
http://msdn.microsoft.com/library/d...ongpathname.asp
http://www.activevb.de/rubriken/api...gpathnamea.html

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Matt Theule" <usenet at mattsolutions dot com_> wrote in message
news:u5rc1v0nDHA.3700@.TK2MSFTNGP11.phx.gbl...
> I need to be able to allow users to drag files to a list box on a web
> page. To this end, I created a Windows Control and hosted it in a
> WebForm. When the file is dropped onto the listbox, the path of the
> file is truncated down to 8.3 format (with the ~1 at the end). When the
> Windows control is hosted in a windows form (for testing purposes) the
> full path is displayed.
> Is there some setting that will allow the full path to be displayed when
> hosted in a WebForm?
> Alternatively, is there a different way to achieve the desired
> functionality without using a WinForm control?
> And less importantly, when hosted in an WebForm, the control is only
> able to accept 1 file at a time. When hosted in a WinForm, the control
> can accept multiple files. Any ideas?
> Thanks
> private void listBox1_DragEnter(object sender,
> System.Windows.Forms.DragEventArgs e)
> {
> if (e.Data.GetDataPresent(DataFormats.FileDrop))
> e.Effect = DragDropEffects.All;
> else
> e.Effect = DragDropEffects.None;
> }
> private void listBox1_DragDrop(object sender,
> System.Windows.Forms.DragEventArgs e)
> {
> try
> {
> string[] files = null;
> if (e.Data.GetDataPresent(System.Windows.Forms.DataFo rmats.FileDrop))
> {
> files = (string[])e.Data.GetData("FileDrop", true);
> }
> foreach (string s in files)
> {
> listBox1.Items.Add(s);
> }
> }
> catch (Exception exp)
> {
> System.Windows.Forms.MessageBox.Show(exp.Message);
> }
> }
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Thanks for the idea, but calling the API from the web hosted windows
control generated a ReflectionPermissions exception.

I did find that using the Framework wizard to adjust the .Net Security
allowed the full path to be shown without the use of the API. Although
everything at this point is on my development workstation, I had to
adjust the 'Local Intranet' zone to 'Full Trust'. The 'My Computer'
zone was defaulted to 'Full Trust'.

I had previously registered the windows control assembly as trusted, but
that did not make a difference.

Now I have to go figure out what is happening when the trust level is
adjusted.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

0 comments:

Post a Comment