打开文件另存为(文档双击打开另存为)

lxf2023-03-16 10:42:01
公共部分类CountyTown : System。web . ui . page { public string county name = string。空的;//乡镇名称公共字符串文档全名= string.empty//计划全名(含后缀)公共字符串文档名= string.empty//计划名称受保护的void page _ load(对象发送方,eventargse) {if(!IsPostBack) {try {//根据传递的乡镇名称获取文件名countyName = Request["space"];DocumentFullName = "江滩乡台风山洪防御方案。docx ";文档名=文档全名。子字符串(0,documentFullName。LastIndexOf(' . '));} catch(Exception){ document full name = " ";} }//这里放用户代码初始化页面应用word = new Application();键入wordType = word。GetType();docs docs = word。文件;//打开文件类型docsType = docs。GetType();对象文件名=服务器。MapPath(@ " ~ \ UpLoad \ ")+document full name;文档文档=(文档)文档类型。InvokeMember("Open ",BindingFlags。InvokeMethod,null,docs,new Object[]{fileName,true,true });//转换格式,保存为Type docType = doc。GetType();对象保存文件名=服务器。MapPath(@ " \ UpLoad \ ")+document name+"。html ";//string j = " text/JavaScript ";客户端脚本。RegisterClientScriptBlock(GetType(),""," ");//保存HTML(错误:Word无法保存此文件,因为它已在其他地方被打开。 )docType。InvokeMember("SaveAs ",BindingFlags。InvokeMethod,null,doc,new object[] { saveFileName,wdsaveformat . wdformathml });//exit word word type . invoke member(" quit ",bindingflags.invokemethod,null,word,null);回应。重定向(" ~/Upload/" + documentName +"。html”);}回复讨论(解决方案)在你的本地测试中不要打开word文档,关闭打开的word文档。 没有打开word文档?