I have form on which there is browse button , when i clicked it, dialogue box open and i selected a file now the path or file name of that file is to be show on textbox i have written code but file path is not display in text box, i have try to resolve but fail, kindly get me out of this, and there is one thing more, i want to upload it in specfic folder and then download it on my system , please tell me about this also
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.IO;
//using System.Drawing;
using System.ComponentModel;
namespace RIS_2
{
/// <summary>
/// Interaction logic for crud.xaml
/// </summary>
public partial class crud : Window
{
public crud()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
}
private void browse_btn_Click(object sender, RoutedEventArgs e)
{
Stream checkStream = null;
// OpenFileDialog op1 = new OpenFileDialog();
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Multiselect = false;
dlg.Filter = "All Image Files | *.*";
//dlg.Filter = "(*.pfw)|*.pfw|All files (*.*)|*.*";
Nullable<bool> result = dlg.ShowDialog();
// if ((bool)dlg.ShowDialog())
if(result==true)
{
try
{
if ((checkStream = dlg.OpenFile()) != null)
{
// MyImage.Source = new BitmapImage(new Uri(dlg.FileName, UriKind.Absolute));
//listBox1.Items.Add(openFileDialog.FileName);
string filename = dlg.FileName;
tb_file.Text = filename;
// tb_file.AppendText(dlg.FileName.ToString());
MessageBox.Show("Successfully done", filename);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
else
{
MessageBox.Show("Problem occured, try again later");
}
}
}
}