My code here but not working When im draged file to window , window must get file path and save in listbox can u help me ?
private void listbox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effects = DragDropEffects.All;
else
e.Effects = DragDropEffects.None;
}
private void listbox1_Drop(object sender, DragEventArgs e)
{
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
int i;
for (i = 0; i < s.Length; i++)
listbox1.Items.Add(s[i]);
for (i = 0; i < s.Length; i++)
listbox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(s[i]));
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
}
}
void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
string dir = Environment.CurrentDirectory + @"\Files\MyFiles\";
string file = listbox1.SelectedItem.ToString();
System.Diagnostics.Process.Start(dir + file);
}
catch
{
MessageBox.Show("Error Loading File." + Environment.NewLine + "File Not Found.", "Error", MessageBoxButton.OK);
}
}
void b_Click(object sender, RoutedEventArgs e)
{
string fileName = ((Button)sender).Tag.ToString();
System.Diagnostics.Process.Start(fileName);
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
const string sPath = "save.txt";
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
foreach (var item in listbox1.Items)
{
SaveFile.WriteLine(item);
}
SaveFile.Close();
MessageBox.Show("Programs saved!");
}