Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 296445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:32:58+00:00 2026-05-12T06:32:58+00:00

I want to enable drag and drop from our windows forms based application to

  • 0

I want to enable drag and drop from our windows forms based application to Windows Explorer. The big problem: The files are stored in a database, so I need to use delayed data rendering. There is an article on codeproject.com, but the author is using a H_GLOBAL object which leads to memory problems with files bigger than aprox. 20 MB. I haven’t found a working solution for using an IStream Object instead. I think this must be possible to implement, because this isn’t an unusual case. (A FTP program needs such a feature too, for example)

Edit: Is it possible to get an event when the user drops the file? So I could for example copy it to temp and the explorer gets it from there? Maybe there is an alternative approach for my problem…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:32:58+00:00Added an answer on May 12, 2026 at 6:32 am

    AFAIK, there is not working article about this for .net. So you should write it by yourself, this is somewhat complicate, because .net DataObject class is limited. I have working example of the opposite task (accepting delayed rendering files from explorer), but it is easier, because I do not needed own IDataObject implementation.

    So your task will be:

    1. Find working IDataObject implementation in .net. I recommend you look here (Shell Style Drag and Drop in .NET (WPF and WinForms))
    2. You also need an IStream wrapper for managed stream (it is relatively easy to implement)
    3. Implement delayed rendering using information from MSDN (Shell Clipboard Formats)

    This is the starting point, and in general enough information to implement such feature. With bit of patience and several unsuccessful attempts you will do it 🙂

    Update: The following code lacks many necessary methods and functions, but the main logic is here.

    // ...
    
    private static IEnumerable<IVirtualItem> GetDataObjectContent(System.Windows.Forms.IDataObject dataObject)
    {
      if (dataObject == null)
        return null;
    
      List<IVirtualItem> Result = new List<IVirtualItem>();
    
      bool WideDescriptor = dataObject.GetDataPresent(ShlObj.CFSTR_FILEDESCRIPTORW);
      bool AnsiDescriptor = dataObject.GetDataPresent(ShlObj.CFSTR_FILEDESCRIPTORA);
    
      if (WideDescriptor || AnsiDescriptor)
      {
        IDataObject NativeDataObject = dataObject as IDataObject;
        if (NativeDataObject != null)
        {
          object Data = null;
          if (WideDescriptor)
            Data = dataObject.GetData(ShlObj.CFSTR_FILEDESCRIPTORW);
          else
            if (AnsiDescriptor)
              Data = dataObject.GetData(ShlObj.CFSTR_FILEDESCRIPTORA);
    
          Stream DataStream = Data as Stream;
          if (DataStream != null)
          {
            Dictionary<string, VirtualClipboardFolder> FolderMap =
              new Dictionary<string, VirtualClipboardFolder>(StringComparer.OrdinalIgnoreCase);
    
            BinaryReader Reader = new BinaryReader(DataStream);
            int Count = Reader.ReadInt32();
            for (int I = 0; I < Count; I++)
            {
              VirtualClipboardItem ClipboardItem;
    
              if (WideDescriptor)
              {
                FILEDESCRIPTORW Descriptor = ByteArrayHelper.ReadStructureFromStream<FILEDESCRIPTORW>(DataStream);
                if (((Descriptor.dwFlags & FD.FD_ATTRIBUTES) > 0) && ((Descriptor.dwFileAttributes & FileAttributes.Directory) > 0))
                  ClipboardItem = new VirtualClipboardFolder(Descriptor);
                else
                  ClipboardItem = new VirtualClipboardFile(Descriptor, NativeDataObject, I);
              }
              else
              {
                FILEDESCRIPTORA Descriptor = ByteArrayHelper.ReadStructureFromStream<FILEDESCRIPTORA>(DataStream);
                if (((Descriptor.dwFlags & FD.FD_ATTRIBUTES) > 0) && ((Descriptor.dwFileAttributes & FileAttributes.Directory) > 0))
                  ClipboardItem = new VirtualClipboardFolder(Descriptor);
                else
                  ClipboardItem = new VirtualClipboardFile(Descriptor, NativeDataObject, I);
              }
    
              string ParentFolder = Path.GetDirectoryName(ClipboardItem.FullName);
              if (string.IsNullOrEmpty(ParentFolder))
                Result.Add(ClipboardItem);
              else
              {
                VirtualClipboardFolder Parent = FolderMap[ParentFolder];
                ClipboardItem.Parent = Parent;
                Parent.Content.Add(ClipboardItem);
              }
    
              VirtualClipboardFolder ClipboardFolder = ClipboardItem as VirtualClipboardFolder;
              if (ClipboardFolder != null)
                FolderMap.Add(PathHelper.ExcludeTrailingDirectorySeparator(ClipboardItem.FullName), ClipboardFolder);
            }
          }
        }
      }
    
      return Result.Count > 0 ? Result : null;
    }
    
    // ...
    
    public VirtualClipboardFile : VirtualClipboardItem, IVirtualFile
    {
      // ...
    
    public Stream Open(FileMode mode, FileAccess access, FileShare share, FileOptions options, long startOffset)
    {
      if ((mode != FileMode.Open) || (access != FileAccess.Read))
        throw new ArgumentException("Only open file mode and read file access supported.");
    
      System.Windows.Forms.DataFormats.Format Format = System.Windows.Forms.DataFormats.GetFormat(ShlObj.CFSTR_FILECONTENTS);
      if (Format == null)
        return null;
    
      FORMATETC FormatEtc = new FORMATETC();
      FormatEtc.cfFormat = (short)Format.Id;
      FormatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT;
      FormatEtc.lindex = FIndex;
      FormatEtc.tymed = TYMED.TYMED_ISTREAM | TYMED.TYMED_HGLOBAL;
    
      STGMEDIUM Medium;
      FDataObject.GetData(ref FormatEtc, out Medium);
    
      try
      {
        switch (Medium.tymed)
        {
          case TYMED.TYMED_ISTREAM:
            IStream MediumStream = (IStream)Marshal.GetTypedObjectForIUnknown(Medium.unionmember, typeof(IStream));
            ComStreamWrapper StreamWrapper = new ComStreamWrapper(MediumStream, FileAccess.Read, ComRelease.None);
    
            // Seek from beginning
            if (startOffset > 0)
              if (StreamWrapper.CanSeek)
                StreamWrapper.Seek(startOffset, SeekOrigin.Begin);
              else
              {
                byte[] Null = new byte[256];
                int Readed = 1;
                while ((startOffset > 0) && (Readed > 0))
                {
                  Readed = StreamWrapper.Read(Null, 0, (int)Math.Min(Null.Length, startOffset));
                  startOffset -= Readed;
                }
              }
    
            StreamWrapper.Closed += delegate(object sender, EventArgs e)
            {
              ActiveX.ReleaseStgMedium(ref Medium);
              Marshal.FinalReleaseComObject(MediumStream);
            };
    
            return StreamWrapper;
          case TYMED.TYMED_HGLOBAL:
            byte[] FileContent;
    
            IntPtr MediumLock = Windows.GlobalLock(Medium.unionmember);
            try
            {
              long Size = FSize.HasValue ? FSize.Value : Windows.GlobalSize(MediumLock).ToInt64();
              FileContent = new byte[Size];
              Marshal.Copy(MediumLock, FileContent, 0, (int)Size);
            }
            finally
            {
              Windows.GlobalUnlock(Medium.unionmember);
            }
            ActiveX.ReleaseStgMedium(ref Medium);
    
            Stream ContentStream = new MemoryStream(FileContent, false);
            ContentStream.Seek(startOffset, SeekOrigin.Begin);
    
            return ContentStream;
          default:
            throw new ApplicationException(string.Format("Unsupported STGMEDIUM.tymed ({0})", Medium.tymed));
        }
      }
      catch
      {
        ActiveX.ReleaseStgMedium(ref Medium);
        throw;
      }
    }
    
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 145k
  • Answers 145k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer When you read the Subversive documentation on Refactoring, you do… May 12, 2026 at 8:54 am
  • Editorial Team
    Editorial Team added an answer This module.xml file is in a folder named "Images". All… May 12, 2026 at 8:54 am
  • Editorial Team
    Editorial Team added an answer I do the following on every build...continuous integration with NAnt/CruiseControl.net… May 12, 2026 at 8:54 am

Related Questions

I have a Flex3 project with 2 HorizontalList controls; one of which has drag
Is there some way to enable Visual Studio 2008 to accept dropped files from
I'm using VS2008 C# Express and the Northwind database on a Windows Form application.
I'm new to JQuery, so this is probably a very dumb question. I've used
The code below enables a control (a label for instance) to show drag images

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.