|
Dear All,
I am developing an application where i need to browse for folder as
I have a browse button when i click in the button, "Browse For Folder" Dialog Box should appear which lists only folders.
and plz let me know how can i upload images to my msgs.
Your cooperation is really appreciated.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
|
thanks alot it did work.
very funny
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
So you need a Folder, to choose the folder you need to Browse, to browse you need a Dialog So you need FolderBrowseDialog
|
|
|
|
|
|
Hi!
I have a result from a query where one parameter is always ParameterName and a string.
e.g
ParameterName = ID, ParameterValue = 123
ParameterName = Name, ParameterValue = Eza
Furthermore I have a class which looks like this:
{public double ID {get;set}
public string Name {get;set;}
What I need to do is something like this:
foreach (var item in result)
{
if (item.PropertyName == "ID")
c.ID = item.PropertyValue;
else if (item.PropertyName == "Name")
c.Name == item.PropertyValue;
}
Anyway there must be a smarter approach - the way I get the Data is given and cannot be changed, unfortunately.
The Ideal solution would be to compare the name of the property with the string item.PropertyName:
eg:
foreach (var item in result)
{
c.ID = item.Where(item.ProperyName == c.ID.ToString());
}
How would you solve this?
modified on Wednesday, November 5, 2008 6:13 AM
|
|
|
|
|
It could be done with reflection, but the code gets a bit complicated and slow as you have different data types to care for and all... I would just write code to check the name and parse the data into the correct type to put in the property:
foreach (var item in result) {
switch(item.PropertyName) {
case "ID": c.ID = double.Parse(item.PropertyValue); break;
case "Name": c.Name = item.PropertyValue;
}
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi all,
I'm currently trying to receive replies to a UDP broadcast that I sent and I can't get it to work. I know the datagrams are sent as I see them with WireShark, but my C# code does not see them.
Here is how I intended things to work:
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try
{
// Send data to the broadcast address
IPEndPoint broadcastIEP = new IPEndPoint(IPAddress.Broadcast, port);
socket.Connect(broadcastIEP);
socket.Send(data);
// Wait for someone to respond
for (int i = 0; i < 50; i++)
{
int availableBytes = socket.Available;
if (availableBytes > 0)
{
byte[] buffer = new byte[availableBytes];
socket.Receive(buffer, 0, availableBytes, SocketFlags.None);
return ASCIIEncoding.ASCII.GetString(buffer);
}
System.Threading.Thread.Sleep(100);
}
return "Nobody replied";
}
finally
{
socket.Close();
}
The intent is to send a UDP broadcast and wait for the first machine that replies. The wait should stop after a while.
I must be doing something wrong here, but I'm quite lost as to what I should be doing. I tried "ReceiveFrom", but it is a blocking call and it never seems to return. I see the datagrams coming through (using WireShark) but ReceiveFrom does not return.
Thanks for your help
Cheers
Olivier
|
|
|
|
|
I don't think you can receive on the broadcast socket
You should have another socket receiving replies.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually, no, this is not possible as one cannot listen on the same port as the sender socket.
I fiddle around a bit more and eventually found a solution: Using Send was the culprit, once I used SendTo, it worked with Receive. However I had to set the options on the socket to avoid an exception being triggered when calling SendTo. So in the end, the code looks like this:
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try
{
byte[] data = new byte[122];
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
socket.SendTo(data, new IPEndPoint(IPAddress.Broadcast, port));
for (int i = 0; i < 100; i++)
{
int availableBytes = socket.Available;
if (availableBytes > 0)
{
byte[] buffer = new byte[availableBytes];
socket.Receive(buffer, 0, availableBytes, SocketFlags.None);
return ASCIIEncoding.ASCII.GetString(buffer);
}
System.Threading.Thread.Sleep(100);
}
return "Nothing found";
}
finally
{
socket.Close();
}
With this, I get the answers to the broadcast request I sent.
Cheers
Olivier
|
|
|
|
|
Hi All
I'm sorry if this is a dumb question, I'm a newbie to .NET programming...
I have a windows app with a treeview control displaying a section of the file system (folders and files).
What I would like to do is drag and drop files from the desktop for example onto a treeview node to copy that file into the relevant folder, just like with windows explorer. I have found plenty of articles on drag and drop between treeviews and list boxes and databases etc, but nothing for files.
Is there anybody out there who can help me???
Thanks in advance...
|
|
|
|
|
|
Thanks for this, but its not quite what I'm looking for, and I'm starting to think it may not be possible.
I want to drag files from outside my app into the treeview within my app. I may well be wrong, but it appears that drag and drop can only be performed between controls in the same application.
Just for background info, the application is project managing software. Projects can be created, tracked etc. The app creates a set of folders on a network drive under the projects unique ID. The TreeView shows the files and folders within the projects own file structure. I want users to be able to drag items from their local machine or network drives into the relevant folders within the app's projects folder tree to keep everything centralised...
Any idea's would be greatly appreciated.
Thank you...
|
|
|
|
|
My appologies, I took presumption that you were merely after same application drag and drop functionality. In short, it is possible, as I use this functionality on some code I wrote 3 years back. Unfortunately, this code is at home (and I'm currently in a training course).
However I did find this, which should give you a step in the right direction:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=192&AspxAutoDetectCookieSupport=1[^]
|
|
|
|
|
This works for me
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
treeView1.AllowDrop = true;
}
private void treeView1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
}
}
}
private void treeView1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.None;
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
}
}
}
[edit] I've read that this will sometimes not work under Vista (not got Vista here to try it) when debugging from the IDE. Build the exe and run independantly and it should be OK. [/edit]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
modified on Wednesday, November 5, 2008 7:36 AM
|
|
|
|
|
Thats mint. Just what I needed.
Thanks to both of you.
|
|
|
|
|
I want to communicate between two forms one is written by me and other is already written by someone but i have executable file only.
I want to extract data from the Textbox of other form not developed by me
My form is in C# 2.0 and the other is where as i think is written VB6.0. I will appriciate if anyone can provide me an example
thanks
|
|
|
|
|
|
Sorry but i am not able to do it.
Can i have an example of getting text from another application form running as separate process
If so please help me and I'll be very thankful to you if you provide me a C# 2003/2005 project
I will be waiting for your reply
|
|
|
|
|
I can't do it for you but I have given you enough keywords for you to search and explore. There are several articles at codeproject that show how to do it.
|
|
|
|
|
So you are voting one because I didn't do your work? This will not encourage any member to help you
|
|
|
|
|
I am sorry i hurt you but i was not intended to do so
I just vote the material is not helping but i appreciate your consideration for intime and first reply
Thanks a lot
Again i will say sorry
|
|
|
|
|
I current can crop certain part of the colour image using
Rectangle rect = new Rectangle(btmX, btmY, rectWidth, rectHeight);
//reading image to graphics
Graphics g = Graphics.FromImage(selectedImg);
//drawing with red pen width 1
Pen pen = new Pen(Color.Red, 1);
//e.Graphics.DrawRectangle(pen, rect);
//drawing the rectangle here
g.DrawRectangle(pen, rect);
picBoxOpen.Image = selectedImg;
//g.Dispose();
but once i crop a grayscaled Image it gave me this problem
+ $exception {"A Graphics object cannot be created from an image that has an indexed pixel format."} System.Exception
I'm kind of new in this image processing area can any kind souls help me out with this please :P thanks
|
|
|
|
|
Cropping an image is one thing... but why are you drawing a red rectangle on the image? From what I can see, the usage of a color outside of the image's pallette range is what is causing your current error, but I certainly cannot see from first glance why you are even using it.
|
|
|
|
|
Oh, cause my program I want to enable a selection for users, using mouse down and mouse up event for users to select the part they wanan crop and a rectangle will be drawn once they selected the part to crop
|
|
|
|