阅读Asp.net中的doc和Docx文件 [英] Read doc and Docx file in Asp.net

查看:119
本文介绍了阅读Asp.net中的doc和Docx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



先生





我想在LocalServer上传一个docx文件然后它的工作正常但是每当我尝试在Web服务器上传相同的(docx)文件时它会生成一个

Hi,
sir


I am trying to upload a docx file in the LocalServer then its works fine but
whenever i try to upload the same(docx) file in the web server it generate one

Error"Retrieving the Com class factory for component with CLSID{000209FF-0000-0000-c0000-000000000046} failed due to the following error:80040154"





先生,根据你的建议,我已附上Microsoft Word 12.0对象库并编写以下代码: -





sir, According your suggestion i have attache Microsoft Word 12.0 Object Library and Write this following code:-

Word.ApplicationClass oWordApp = new Word.ApplicationClass();
           //Word.ApplicationClass wordApp = new Word.ApplicationClass();
           object file = path;
           object nullobj = System.Reflection.Missing.Value;
           Word.Document doc = wordApp.Documents.Open(
           ref file, ref nullobj, ref nullobj,
           ref nullobj, ref nullobj, ref nullobj,
           ref nullobj, ref nullobj, ref nullobj,
           ref nullobj, ref nullobj, ref nullobj);
           //d1.InnerHtml = doc.Content.Text;
           TextBox2.Text = doc.Content.Text;
           wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);



请帮帮我先生,<罢工>我非常紧急



关于Nandita Gupta


Please help me sir, I quite urgent

Regards Nandita Gupta

推荐答案

您好以上代码在Windows应用程序中运行良好。我们运行源代码时工作正常。一旦我们在iis6或更高版本中部署站点,它就无法工作。经过长时间的实验(比如改变DCOM组件中的身份,最终启动权限,它在windows xp和iis5.1上工作。所以它不好。然后我们改变了我们的代码我跳过另一个dll即

Hi the above code works good in windows application . working good when we run with source code. its not working once we deploy site in iis6 or above. after doing long experiment (like changing identity in DCOM components, launch permissions finally its working on windows xp and iis5.1. So its not good. then we have changed our code i skipped to another dll i.e
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;



和这些dll的问题仅适用于.docx。



有任何其他方式阅读.doc文件



我的服务器:Windows 2007

iis:6


and problem with these dlls is its working for .docx only.

is there any other way to read .doc file

My Server: windows 2007
iis : 6


尝试以下代码



Try the following code

FileStream fstream = new
FileStream("filePath\Sample.doc",FileMode.Open,FileAccess.Read);
StreamReader sreader = new StreamReader(fstream);

txtFileContent.Text = sreader.ReadToEnd();






你可以尝试这个 C#/ VB.NET Word 组件 C#读取DOCX



这是一个示例C#代码如何在ASP中读取上传的DOCX .NET并将其内容输出到多行TextBox:

Hi,

you can try this C# / VB.NET Word component to C# read DOCX.

Here is a sample C# code how to read an uploaded DOCX in ASP.NET and output its content to multiline TextBox:
// Load a document from a Stream contained in FileUpload control.
var document = DocumentModel.Load(FileUploadControl.FileContent, LoadOptions.DocxDefault);

// Initialize new StringBuilder.
var sb = new StringBuilder();

// Iterate over all paragraphs in the document and append new line to StringBuilder.
foreach (Paragraph paragraph in document.GetChildElements(true, ElementType.Paragraph))
{
	// Iterate over all text elements in the parent paragraph and append its text to StringBuilder.
	foreach (Run run in paragraph.GetChildElements(true, ElementType.Run))
		sb.Append(run.Text);
	sb.AppendLine();
}

// Assign a StringBuilder text to TextBox2 control.
TextBox2.Text = sb.ToString();


这篇关于阅读Asp.net中的doc和Docx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆