Click here to Skip to main content
15,921,697 members
Home / Discussions / C#
   

C#

 
GeneralRe: Adding Class to System.Collections? Pin
Doncp25-Dec-05 10:21
Doncp25-Dec-05 10:21 
GeneralRe: Adding Class to System.Collections? Pin
Judah Gabriel Himango26-Dec-05 9:07
sponsorJudah Gabriel Himango26-Dec-05 9:07 
QuestionHow can i create a html file? Pin
CursedXp25-Dec-05 4:39
CursedXp25-Dec-05 4:39 
AnswerRe: How can i create a html file? Pin
Stanciu Vlad25-Dec-05 7:29
Stanciu Vlad25-Dec-05 7:29 
QuestionCopying File Names from Explorer Pin
redfish3424-Dec-05 23:24
redfish3424-Dec-05 23:24 
AnswerRe: Copying File Names from Explorer Pin
Judah Gabriel Himango25-Dec-05 8:35
sponsorJudah Gabriel Himango25-Dec-05 8:35 
GeneralRe: Copying File Names from Explorer Pin
redfish3425-Dec-05 16:04
redfish3425-Dec-05 16:04 
AnswerFOUND SOLUTION Pin
redfish3425-Dec-05 22:28
redfish3425-Dec-05 22:28 
It took some trial and error. The big hurdle was getting the Win32 DragQueryFile() PInvoke signature right. I had found a signature on the internet but it was wrong. Below is the code you need to transfer file paths to your app when you do copy-cut-paste of folders and files. I decided to use the Win32 IsClipboardFormatAvailable() instead of the NET equivalent (IDataObject/GetDataPresent) to keep code clean. The NET 1.1 implementation of the clipboard is pretty poor IMO. To make use of the code, you call ClipboardGetFiles() and get returned a string array containing the file paths.

HTH someone. I am amazed i could not find any examples to do this in C#.

// Get an array of the files listed in the clipboard.
private string[] ClipboardGetFiles()
{
string[] fileList = null;

// Make sure there is file data.
if (IsClipboardFormatAvailable(CF_HDROP))
{
// File data exists. Get it.
// Open the clipboard.
System.IntPtr hClipboard = System.IntPtr.Zero;
if (OpenClipboard(hClipboard) == true)
{
// get handle to dropped file list
System.IntPtr hDropList = System.IntPtr.Zero;
hDropList = GetClipboardData(CF_HDROP);

// get the number of dropped files
long fileCount;
fileCount = DragQueryFile(hDropList, -1, null, 0);

// get the file names
fileList = new string[fileCount];
const int MAX_PATH = 260;
for (int i = 0; i < fileCount; i++)
{
// Get the file name.
System.Text.StringBuilder fileName = new System.Text.StringBuilder();
fileName.Capacity = MAX_PATH;
DragQueryFile(hDropList, i, fileName, MAX_PATH);
fileList[i] = fileName.ToString();
}

// Close the clipboard.
CloseClipboard();
}
}
// Assign the return value.
return fileList;
}

// found that NET clipboard functionality is both limited and
// incompatible with clipboard functionality of windows OS;
// will use interoperate with win32 to get needed functionality;

// Clipboard routines.

// OpenClipboard
// CloseClipboard
// IsClipboardFormatAvailable
// GetClipboardData
// DragQueryFile

// file list clipboard format code.
const int CF_HDROP = 15;

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool OpenClipboard(System.IntPtr hwnd);

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool CloseClipboard();

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool IsClipboardFormatAvailable(uint format);

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern System.IntPtr GetClipboardData(uint uFormat);

[System.Runtime.InteropServices.DllImport("shell32.dll")]
static extern uint DragQueryFile(
IntPtr hDrop,
int iFile,
System.Text.StringBuilder fName,
int fnSize);
QuestionIE Menu Extension Pin
ghost120724-Dec-05 22:52
ghost120724-Dec-05 22:52 
QuestionPassing a class by value, but reversed? Pin
monrobot1324-Dec-05 20:25
monrobot1324-Dec-05 20:25 
AnswerRe: Passing a class by value, but reversed? Pin
S. Senthil Kumar25-Dec-05 1:36
S. Senthil Kumar25-Dec-05 1:36 
Questionprogramatically creating control instances Pin
Pyro Joe24-Dec-05 15:51
Pyro Joe24-Dec-05 15:51 
AnswerRe: programatically creating control instances Pin
Luke Davis24-Dec-05 16:24
Luke Davis24-Dec-05 16:24 
GeneralRe: programatically creating control instances Pin
Pyro Joe25-Dec-05 5:33
Pyro Joe25-Dec-05 5:33 
QuestionHow start a application at beginning windows(about registry) Pin
Developer_124-Dec-05 14:35
Developer_124-Dec-05 14:35 
AnswerRe: How start a application at beginning windows(about registry) Pin
Developer_124-Dec-05 21:52
Developer_124-Dec-05 21:52 
AnswerRe: How start a application at beginning windows(about registry) Pin
S. Senthil Kumar25-Dec-05 1:38
S. Senthil Kumar25-Dec-05 1:38 
QuestionVoice input in C# Pin
rajajee24-Dec-05 6:03
rajajee24-Dec-05 6:03 
QuestionNeed help for Parsing HTML Pin
dr_hema24-Dec-05 6:03
dr_hema24-Dec-05 6:03 
QuestionGetting .NET types programaticly? Pin
mikker_12324-Dec-05 3:09
mikker_12324-Dec-05 3:09 
AnswerRe: Getting .NET types programaticly? Pin
[Marc]24-Dec-05 4:19
[Marc]24-Dec-05 4:19 
QuestionASync Sockets Throwing Strange Exception Pin
ColonelSanders24-Dec-05 2:21
ColonelSanders24-Dec-05 2:21 
AnswerRe: ASync Sockets Throwing Strange Exception Pin
ColonelSanders24-Dec-05 18:00
ColonelSanders24-Dec-05 18:00 
QuestionColoring rows in DataGrid Pin
Yoyosch23-Dec-05 23:22
Yoyosch23-Dec-05 23:22 
Questiontransfer my inbox mails to database Pin
sreesiri23-Dec-05 19:22
sreesiri23-Dec-05 19:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.