public static string GetMimeType(string fileName) { if (!string.IsNullOrEmpty(fileName)) { string ext = Path.GetExtension(fileName).ToLowerInvariant(); if (!string.IsNullOrEmpty(ext)) { string mimeType = MimeTypes.GetMimeType(ext); if (!string.IsNullOrEmpty(mimeType)) { return(mimeType); } mimeType = RegistryHelpers.GetRegistryValue(ext, "Content Type", RegistryHive.ClassesRoot); if (!string.IsNullOrEmpty(mimeType)) { return(mimeType); } } } return(MimeTypes.DefaultMimeType); }
private void SavePaper() { //从注册表寻找pmp文件的位置 string keyPath = @"Software\Autodesk\AutoCAD\R22.0\ACAD-1001:804"; string keyName = "RoamableRootFolder"; object FindPC3_Path = RegistryHelpers.GetRegistryValue(keyPath, keyName); string pmp_path = (string)FindPC3_Path + "Plotters\\PMP Files\\"; PrinterSetting paper = new PrinterSetting(); DB.BLL.PAPER_SIZE papers = new DB.BLL.PAPER_SIZE(); DataSet papers_list = papers.GetList("1=1"); DataTable row = papers_list.Tables[0]; foreach (DataGridViewRow r in dgv_PaperSizeList.Rows) { paper.PaperX = Convert.ToDouble(r.Cells[2].Value) * 10; paper.PaperY = Convert.ToDouble(r.Cells[3].Value) * 10; paper.userdef_name = (string)r.Cells[1].Value; //三个打印机,添加三次 paper.AddPrinter(pmp_path + "DWG To PDF.pmp"); paper.AddPrinter(pmp_path + "PublishToWeb JPG.pmp"); paper.AddPrinter(pmp_path + "PublishToWeb PNG.pmp"); } }
private void button_DeletPaper_Click(object sender, EventArgs e) { //从注册表寻找pmp文件位置 string keyPath = @"Software\Autodesk\AutoCAD\R22.0\ACAD-1001:804"; string keyName = "RoamableRootFolder"; object FindPC3_Path = RegistryHelpers.GetRegistryValue(keyPath, keyName); string pmp_path = (string)FindPC3_Path + "Plotters\\PMP Files\\"; //从数据库删除 DB.BLL.PAPER_SIZE bll = new DB.BLL.PAPER_SIZE(); DataGridViewSelectedRowCollection rows = dgv_PaperSizeList.SelectedRows; foreach(DataGridViewRow r in rows) { string PAPER_NAME = (string)r.Cells[1].Value; bll.Delete(PAPER_NAME); //删除纸张 PrinterTool.RemovePrinters(pmp_path + "DWG To PDF.pmp", new string[] { PAPER_NAME }); PrinterTool.RemovePrinters(pmp_path + "PublishToWeb JPG.pmp", new string[] { PAPER_NAME }); PrinterTool.RemovePrinters(pmp_path + "PublishToWeb PNG.pmp", new string[] { PAPER_NAME }); } Init_dgv_PaperSizeList(); }
/// <summary> /// 附着pmp路径到pc3内 /// </summary> /// <param name="plotDevice">当前调用的打印机</param> /// <param name="dwgtopdfpmp">pmp路径</param> public void ChangUserDefinedModel(string plotDevice, string dwgtopdfpmp) { //获取这个打印机的完整路径 string keyPath = @"Software\Autodesk\AutoCAD\R22.0\ACAD-1001:804"; string keyName = "RoamableRootFolder"; object FindPC3_Path = RegistryHelpers.GetRegistryValue(keyPath, keyName); string printerConfigDir = FindPC3_Path + "Plotters\\" + plotDevice; var ns = new string[] { printerConfigDir, dwgtopdfpmp }; foreach (var path in ns) { if (!File.Exists(path)) { continue; } var PdfConfig = new PlotterConfiguration(path); //解压了打印机信息之后,遍历打印机节点 foreach (var nodeA in PdfConfig) { if (nodeA.NodeName == "meta") { nodeA.ValueChang("user_defined_model_pathname" + "_str", dwgtopdfpmp); break; } } PdfConfig.Saves(); } }