帮助我,我知道如何组合这段代码。希望任何人都可以帮助我。我在 asp.net 中使用 c# 并尝试将 .doc 和 .docx 转换为 html 以在网页中查看。
这是我的代码:
public bool WriteViewRow(DataRowView drv)
{
string strFileLink = null;
string strFileName = Convert.ToString(drv["Name"]);
string strFilePath = WebPathCombine(WebPath(), strFileName);
bool blnFolder = IsDirectory(drv);
if (blnFolder)
{
if (!string.IsNullOrEmpty(_strHideFolderPattern) && Regex.IsMatch(strFileName, _strHideFolderPattern, RegexOptions.IgnoreCase))
{
return false;
}
strFileLink = PageUrl(strFilePath) + strFileName + "</A>";
}
else
{
if (!string.IsNullOrEmpty(_strHideFilePattern) && Regex.IsMatch(strFileName, _strHideFilePattern, RegexOptions.IgnoreCase))
{
return false;
}
strFileLink = "<A href=\"" + strFilePath + "\" target = \"iframe01\">" + strFileName + "</A>"; //link to open the file
}
我想用这个代码加入我的代码,我不想上传文件,但想使用上面代码中的链接来集成到这个代码中:
//To check the file extension if it is word document or something else
string strFileName = fUpload.FileName;
string[] strSep = fUpload.FileName.Split('.');
int arrLength = strSep.Length - 1;
string strExt = strSep[arrLength].ToString().ToUpper(); //Save the uploaded file to the folder
strPathToUpload = Server.MapPath("Datadir"); //Map-path to the folder where html to be saved
strPathToConvert = Server.MapPath("WordToHtml");
object FileName = strPathToUpload + "\\" + fUpload.FileName;
object FileToSave = strPathToConvert + "\\" + fUpload.FileName + ".htm";
if (strExt.ToUpper() == "DOCX" || strExt.ToUpper() == "DOC" )
{
fUpload.SaveAs(strPathToUpload + "\\" + fUpload.FileName);
lblMessage.Text = "File uploaded successfully";
//open the file internally in word. In the method all the parameters should be passed by object reference
objWord.Documents.Open(ref FileName, ref readOnly, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing,
ref missing, ref missing);
//Do the background activity
objWord.Visible = false;
Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
oDoc.SaveAs(ref FileToSave, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
lblMessage.Text = fUpload.FileName + " converted to HTML successfully";
docPreview.Attributes["src"] = "../WordToHtml/" + fUpload.FileName + ".htm";
}
有人有什么建议吗?实际上我想开发一些像 webmanager 这样的网页,并且用户能够上传、删除、查看、编辑文件。如果文件 .txt 已经完成了。但是我无法转换它。