depaa
asked on
conversion of word to html through Microsoft office Library
conversion of word to html through Microsoft.Office.Interop.W ord.Applic ationClass is working fine when i am running my website through visual studio, but when i run the same in the same website through IIS 7 , Conversion of word to html is not working ?
I am calling a WebMethod for conversion of word to html through javascript. I have tested by putting OnSucess and OnFailure Function in javascript to check is it working or not .
Through Visual Studio - OnSucess function is executed
Through IIS - OnFailure function is executed
I am calling a WebMethod for conversion of word to html through javascript. I have tested by putting OnSucess and OnFailure Function in javascript to check is it working or not .
Through Visual Studio - OnSucess function is executed
Through IIS - OnFailure function is executed
Web Method
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function Convert(ByVal inputHtml As String) As String
Dim objWord As Microsoft.Office.Interop.Word.ApplicationClass
Dim doc As String = inputHtml
Dim splitHtml As String() = doc.Split(New Char() {"/"c})
Dim splitvalue As String
splitvalue = splitHtml(splitHtml.Length - 3) + "\" + splitHtml(splitHtml.Length - 2) + "\" + splitHtml(splitHtml.Length - 1)
Dim Splitcheck As String() = splitHtml(splitHtml.Length - 1).Split(New Char() {"."c})
Dim path2Convert = System.Web.HttpContext.Current.Server.MapPath(".\" + splitHtml(splitHtml.Length - 3) + "\" + splitHtml(splitHtml.Length - 2) + "\" + Splitcheck(Splitcheck.Length - 2) + ".html")
If (System.IO.File.Exists(path2Convert)) Then
Else
Try
Dim strWordDoc = inputHtml
Dim strHTMLDoc = path2Convert
objWord = CreateObject("Word.Application")
objWord.Visible = False
objWord.Documents.Open(strWordDoc)
Dim FileFormat
Dim LockComments
Dim Password
Dim AddToRecentFiles
Dim WritePassword
Dim ReadOnlyRecommended
Dim EmbedTrueTypeFonts
Dim SaveNativePictureFormat
Dim SaveFormsData
Dim SaveAsAOCELetter
FileFormat = 8
LockComments = True
Password = ""
AddToRecentFiles = False
WritePassword = ""
ReadOnlyRecommended = False
EmbedTrueTypeFonts = False
SaveNativePictureFormat = True
SaveFormsData = False
SaveAsAOCELetter = False
objWord.ActiveDocument.SaveAs(strHTMLDoc, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter)
objWord.ActiveDocument.Close()
objWord.Quit()
objWord = Nothing
Catch ex As Exception
'objWord.ActiveDocument.Close()
'objWord.Quit()
'objWord = Nothing
End Try
End If
Return inputHtml
End Function
Javascript Code -
function AssignPath(strPath,strDocType,intDocId,strUploadId)
{
path=strPath;
var PathSplit;
PathSplit = path.split('.');
if ((PathSplit[PathSplit.length - 1] == "doc") || (PathSplit[PathSplit.length - 1] == "docx")) {
PageMethods.Convert(path, OnSucess, OnFailure);
var output = path.substr(0, path.lastIndexOf('.'));
path = output + ".html";
function OnSucess(result) {
alert(path);
}
function OnFailure() {
alert("Conversion Failed");
}
}
}
Almost certainly it's security-related issue, where IIS has less permissions than you. While it's hard to tell blindly what exactly is going on, I would look into (1) details of the exception raised by OnFailure, if any are available; then look in the event log, if there's anything generated at the time when this happens; then you can invoke audit policy /audit object access in Local security policy, and look at the events that will be generated.
ASKER
We have solved this with advice from other experts
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
We waited for quite some time and did not get the help in time.
We solved it ourselves using one way and the other way was from advice from another forum.
We solved it ourselves using one way and the other way was from advice from another forum.
It's good that the author has solved the problem; however, I would like to note that the solution they found really isn't a solution of the problem that was in place here; it's in fact abandoning the original solution and implementing totally different one.
The mere fact that this code was already working in Visual Studio, means that it could be done; Visual Studio creates its own webserver, and the only difference between this webserver and IIS is in the credentials it runs under. With Word, it's quite obvious that if IIS is running under another credential than the user, there could be issues with Word not running on that credential "out of the box", same as it wouldn't run for another user, and might require an installation. Or even if it did run, this might be an issue as trivial as Word on the first launch showing modal dialog box requiring the user to enter the initials - maybe Word "showed" it to IIS. In any case, since the solution already worked on credential A and the matter was to port it to credential B, the most straightforward was to find out the difference between A and B and eliminate it. As a last resort, to try to run IIS with user's credential and allowing the service to interact with the desktop.
The mere fact that this code was already working in Visual Studio, means that it could be done; Visual Studio creates its own webserver, and the only difference between this webserver and IIS is in the credentials it runs under. With Word, it's quite obvious that if IIS is running under another credential than the user, there could be issues with Word not running on that credential "out of the box", same as it wouldn't run for another user, and might require an installation. Or even if it did run, this might be an issue as trivial as Word on the first launch showing modal dialog box requiring the user to enter the initials - maybe Word "showed" it to IIS. In any case, since the solution already worked on credential A and the matter was to port it to credential B, the most straightforward was to find out the difference between A and B and eliminate it. As a last resort, to try to run IIS with user's credential and allowing the service to interact with the desktop.