我使用此代码将数据发送到 Word 模板并发送到客户端。
protected void Button1_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
string DocFilePath = "";
//string FilePath = System.Windows.Forms.Application.StartupPath;
object fileName = Server.MapPath(@"~\asset\wordtemplates\Estelam.dot");
DocFilePath = fileName.ToString();
FileInfo fi = new FileInfo(DocFilePath);
if (fi.Exists)
{
object readOnly = false;
object isVisible = true;
object LetterNo = "LetterNo";
object LetterDate = "LetterDate";
object Attachment = "Attachment";
object To = "To";
object From = "From";
object Fname = "Fname";
object Lname = "Lname";
object FatherName = "FatherName";
object IDNumber = "IDNumber";
object BirthDate = "BirthDate";
object BirthLocation = "BirthLocation";
object PersonelID = "PersonelID";
object MembershipDate = "MembershipDate";
object Membership = "Membership";
object Degree = "Degree";
object Level = "Level";
object Guild = "Guild";
object Janbazi = "Janbazi";
object Esarat = "Esarat";
object Education = "Education";
object Field = "Field";
object Education2 = "Education2";
object DocLocation = "DocLocation";
Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref isVisible, ref isVisible, ref missing, ref missing, ref missing);
//Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName);
WordApp.ActiveDocument.FormFields.get_Item(ref LetterNo).Result = TextBox_LetterNo.Text;
此代码在本地运行良好且正确,但是当我发布此站点并将其放到我的服务器上时,运行时出现此错误。
此命令不可用,因为没有打开文档。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。异常详细信息:System.Runtime.InteropServices.COMException:此命令不可用,因为没有打开文档。
源错误:在执行当前 Web 请求期间产生了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。
为什么服务器打不开?如何解决此错误?
我使用 Windows7、VS2010、SQLServer2008、office2010,在服务器中使用 Windows Server 2008、IIS7、office2010。
我应该为服务器上的这个错误做些什么?