我使用File.Create()新建一个cad文件,可以新建成功,但是文件无法打开。通过File.Create()创建的cad文件始终为0kb,而我通过鼠标右击新建的cad文件一般为10kb,(这点差异可能是导致文件无法打开的原因),我如何在程序中实现像通过鼠标右击新建的功能呢?
我的代码如下:
          String path="D:\\catia.CATProduct";
          File.Create(path).Close();
ps:我新建的cad文件扩展名为:.CATProduct。

解决方案 »

  1.   

    你这个应该调用你应用软件暴露出来的API实现新建文件。
      

  2.   

    可以去找找注册表里类似这种位置
    HKEY_CLASSES_ROOT\.pptx\PowerPoint.Show.12\ShellNew看看能不能找到命令或者文件很多情况其实系统根本就没有创建文件,只是将模板文件复制过来,比如说powerpoint就是这样
      

  3.   

    string path = @"G:\\catia.CATProduct";
    try
    {
    if (File.Exists(path))
    {
    File.Delete(path);
    }
    // Create the file.
    using (FileStream fs = File.Create(path))
    {
    Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
    // Add some information to the file.
    fs.Write(info, 0, info.Length);
    }
    // Open the stream and read it back.
    using (StreamReader sr = File.OpenText(path))
    {
    string s = "";
    while ((s = sr.ReadLine()) != null)
    {
    Console.WriteLine(s);
    }
    }
    }
    catch (Exception Ex)
    {
    Console.WriteLine(Ex.ToString());
    }试了没问题生成30字节  1K 
      

  4.   

    我找到了HKEY_CLASSES_ROOT\.CATProduct\CATIA.CATProduct\ShellNew了,然后我该怎么办呢?
      

  5.   

    文件不是这样创建的,cad文件能这样创建就奇了怪了
    cad文件格式首先你要知道,文件头,文件主体等等,文件内部结构要很清晰才能自己DIY