i making a file transfer (server-client) application ..
i have two listviewS to explore Local PC and Remote PC .. before send/receive the items..
i need to check if there's another file or folder has the same name at the destination path..
when i press on the button [send or receive] the item added to a list.. then when i press on button [Start Transfer] .. it starts.
so the AddItems Method called when i press the button Receive or Send .. i get the SelectedItems from the source ListView .. and the Items of the destination ListView ... then i check for each item in SelectedItems if it is exists in Items
i tried to use
items.Contain(item)
but it didn't work it always gave me false even if the item is already exists.
so i used items.ContainKey and it worked .. but in case that i have a file named "Temp" with no extension and a folder in destination path also named "Temp" .. it will returns True .. and that's my problem ..
bool YesToAll = false;
public void AddItems(ListView.SelectedListViewItemCollection selectedItems, ListView.ListViewItemCollection items,TransferType type,string destPath)
{
foreach(ListViewItem item in selectedItems)
{
if (items.ContainsKey(item.Name) && !YesToAll)
{
MyMessageBox msgbox = new MyMessageBox("Item is already exists .. Do you want to replace (" + item.Text + ") ?");
msgbox.ShowDialog();
if (msgbox.DialogResult == DialogResult.Yes)
{
Add(item, type, destPath);
}
else if (msgbox.DialogResult == DialogResult.OK)
{
YesToAll = true;
Add(item, type, destPath);
}
else if (msgbox.DialogResult == DialogResult.No)
{
continue;
}
else
{
return;
}
}
else
{
Add(item, type, destPath);
}
}
YesToAll = false;
}
private void Add(ListViewItem item,TransferType type,string path)
{
ListViewItem newItem = (ListViewItem)item.Clone();
newItem.ImageIndex = imageList1.Images.Add(item.ImageList.Images[item.ImageIndex],Color.Transparent);
newItem.SubItems.Add(type.ToString());
newItem.SubItems.Add(path);
newItem.Tag = type;
listView1.Items.Add(newItem);
}
YesToAll is set to true when the user clicked on [Yes to all] button in the confirm dialogbox.
TransferType is just to mark the item if it's going to use SendMethod or ReceiveMethod
public enum TransferType
{
Send , Receive
};
so how do i fix that .. should i use a custom method instead of [Contains] that checks for the name and for the type (file or folder) because each item is already has a subItem which tell if it is a folder or a file
thanks in advance.