Wednesday, June 29, 2016

How to get my project path?

private void btn_upload_Click(object sender, EventArgs e)
        {
            OpenFileDialog op1 = new OpenFileDialog();
            op1.Multiselect = true;
            op1.ShowDialog();
            op1.Filter = "allfiles|*.xls";
            textBox1.Text = op1.FileName;
            int count = 0;
            string[] FName;
            foreach (string s in op1.FileNames)
            {
                //string startupPath1 = System.IO.Directory.GetCurrentDirectory();
                //string startupPath = Environment.CurrentDirectory;
                string wanted_path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
                FName = s.Split('\\');
                File.Copy(s, wanted_path + "\\Upload\\ " + FName[FName.Length - 1]);
                count++;
            }
            MessageBox.Show(Convert.ToString(count) + " File(s) copied");

        }