2
Answers

Hi i am using kernel32.dll for creating the files (pdf file)

Hi, i am using kernel32.dll for creating the files in my remote server.
 
i am using default function for creating the files as folllows
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
Calling the above method by referring safefilehandle class like this,
this.Handle = CreateFile(filePath, GENERIC_ALL, FILE_SHARE_READ, IntPtr.Zero, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero);
 
i was able to create a new file but what i observed is that .exe which i was generating a file was not releasing the file and it is saying that it is in open mode. i was unable to access that file for further modification. 
 
 If i restart my .exe at that time it was releasing the file and i was able to do the things. Only when i was creating a new file it was not releasing. 
 
I am making the handle to close the file. Even then also i was unable to do.
 
This is happening only when i was creating a new pdf file in the remote server. 
 
Since i was struck with this, i need a solution very fast.
 
Thanks in advance. 
 

Answers (2)

1
Photo of Bryian Tan
NA 9.4k 887.4k 15y
Hello,

You have to subtract one from the count, because 0 to 19 = 20 counts

string[] ItemArray = new string[20];
for (int i = 0; i <= listBox1.SelectedItems.Count - 1; i++)
{
txtmessage.Text = ((DataRowView)listBox1.SelectedItem).Row.ItemArray[i].ToString();
}


Thanks,
Bryian Tan
Accepted
1
Photo of Anish Khan
NA 25 0 15y

Hi Bryian,
Your answer is good...
But  listBox1.SelectedItems.Count is < 5
and also I am geting error..

Thanks

Anish

0
Photo of Bryian Tan
NA 9.4k 887.4k 15y
Anish,

What is the relationship between the listbox1, ItemArray and the DataView?