Chủ Nhật, 13 tháng 10, 2013

.NET linh tinh code

Mở file theo chương trình mặc định
        Process.Start(openFile);

            int a = 0;
            int.TryParse(drv["Point"] + "", out a);
            CEDiemThi.Value = a;//Convert.ToInt32(drv["Point"] + "");
            txtGhiChu.Text = drv["Note"].ToString();

path thư mục dự án

    private void btnDaoTao_UploadQD_Click(object sender, EventArgs e)
    {
       OpenFileDialog ofd = new OpenFileDialog();
        ofd.Filter = "All file|*.*";
        string exePath =
    System.IO.Path.GetDirectoryName(
       System.Reflection.Assembly.GetEntryAssembly().Location);
      
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            FileInfo fInfo = new FileInfo(ofd.FileName);

            string filename = Path.GetFileName(ofd.FileName);

            string saveFile = exePath + @"\CacFileLienQuan\" + filename;
            if (File.Exists(saveFile)) File.Delete(saveFile);
            fInfo.CopyTo(saveFile);
        }
    }


using System;
using System.IO;

class Program
{
    static void Main()
    {
 string path = "C:\\stagelist.txt";

 string extension = Path.GetExtension(path);
 string filename = Path.GetFileName(path);
 string filenameNoExtension = Path.GetFileNameWithoutExtension(path);
 string root = Path.GetPathRoot(path);

 Console.WriteLine("{0}\n{1}\n{2}\n{3}",
     extension,
     filename,
     filenameNoExtension,
     root);
    }
}

Output

.txt
stagelist.txt
stagelist
C:\

Không có nhận xét nào:

Đăng nhận xét