Office server-side Automation still possible with Office 365? - asp.net

I have an ASP.NET Webforms Application where the user can create reports with server-side office Automation. It basically works with FormFields that are being filled out and in the end the user gets a download with the Office document. The Application is quite old and I did not design this software. I'm also aware of the side effects of office server Automation and this article:
https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office
It just works for almost 15 years with several different Office Versions, the newest one is Office 2016 but now I have to know if it still would work with Office 365. It looks like a hybrid solution, Software as a Service but still requires installation on the machine somehow.
It's a little bit hacky to set up like:
IIS Application User needs to take ownership of the following folder:
C:\Programme(x86)\Microsoft Office
C:\Programme\Microsoft Office
C:\Windows\System32\config\systemprofile\AppData
C:\Windows\System32\config\systemprofile\Desktop (sometimes missing
so it needs to be created)
C:\Windows\SysWOW64\config\systemprofile\AppData
C:\Windows\SysWOW64\config\systemprofile\Desktop (sometimes missing
so it needs to be created)
C:\Programme(x86)\Microsoft.Net\
C:\Program Files (x86)\Microsoft ASP.NET\
And in addition, some DCOM Configuration for Word and Excel needed. The IIS Application User needs permission to start the office application etc.
I'm not sure if all the requiered dependency are still there with office 365.
Here is a code snippet:
Function CreateDoc(ByVal docpath As String, ByVal docname As String, ByVal Document As String) As String
Dim ff_name As String = ""
Dim strFileName As String = Nothing
Dim strExtension As String = Nothing
Dim fileBytes As Byte() = Nothing
Try
Dim w = New Word.Application
w.Visible = m_obj.Project.OfficeDisplay
w.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
w.Documents.Open(docpath)
SetRanges(Document)
Dim i As Integer
For Each ff As Word.FormField In w.ActiveDocument.FormFields
.
.
.

The good news first. If it's work with Office 2016 it should work good with Office 365 too. The bad news now, with the monthly evolution the usage of office interop risk to create issue in the future (in months, or probably more in years), it's difficult without auditing all the solution to give you answer. The next step will be to see if your application could be transform in Web Add-in with offie.js or use Graph API. But unfortunately lot of stuff we do in interop are not possible with the modern solution...

Nothing has been changed so far with desktop editions of Microsoft Office. But I'd recommend using the Open XML SDK for generating documents on the server-side, see Welcome to the Open XML SDK 2.5 for Office for more information.

Related

Locating the source DLL behind a COM+ ProgId

I've never really had to debug Classic ASP, so this is a little rough and most likely a poor question, but I have done as much research as I could before asking.
I have a request to identify what code prints to a printer, and re-use that code in a new page that someone has built.
While trying to identify that, I've stumbled on a few things that I don't understand, but namely one big one.
The gist is, people can order cookies from the cafeteria, and when they submit, it shows a confirmation page and that order is sent to a printer.
To get a list of cookie options, there's a Server Object created, and from there a method exists, but I cannot identify where it is or where I should be looking. Here's the code:
<%
On error resume next
Const CATAGORY_COOKIE = 1
Dim cookieNames
Dim objCookie
Dim Count
Set objCookie = Server.CreateObject("CookieOrder.CookieRequest")
if objCookie Is Nothing then
Response.Write "Error"
Response.End
End if
cookieNames = objCookie.getAvailable_Item_Names(CATAGORY_COOKIE)
Count = objCookie.Count
Dim sz
sz = Split(cookieNames, ";")
Set objCookie = Nothing
%>
How do I identify what the Server Object is? There's a .dll file that contains binary, but I'm not familiar with how that could be utilized.
I have tried to follow the browser dev tools, but they really haven't been too helpful in this aspect.
I am hoping that learning how this code is executing or where it's being executed I will figure out my other problems.
Bit of background
The project is using a COM+ component. These are defined in Classic ASP using the syntax;
Set obj = Server.CreateObject("[insert COM+ ProgId]")
In this project you are using a component registered with the ProgId
CookieOrder.CookieRequest
There are many out of the box COM+ components available to Classic ASP that provide a lot of common functionality such as;
Visual Basic Scripting Runtime
ActiveX Data Objects
There is also the ability to create COM+ components for use with Classic ASP using languages common to the time like Visual Basic, Visual C++ and more recently using the .NET Framework (C#, VB.NET).
How to locate COM+ libraries
NOTE: Please be careful when accessing the registry as modifying or deleting keys could lead to a corrupt operating system.
Also for the purposes of this guide will use the Scripting.Dictionary ProgId.
The key is using the ProgId to find an elusive COM+ library.
Start %SystemRoot%\system32\regedit.exe (will work in most Windows Operating Systems)
Navigate to the HKEY_CLASS_ROOT hive and select it, then press Ctrl + F to open the Find dialog box.
In Find what type the ProgId in this case Scripting.Dictionary and make sure in look at only Key is checked then press Find or Find Next.
If a ProgId key is found expand to the key and locate the CLSID key which contains a (Default) REG_SZ with the value of the CLSID in the case of this example {EE09B103-97E0-11CF-978F-00A02463E06F}. Double click this value to bring up the Edit String dialog copy the value into your clipboard.
Return to the HKEY_CLASS_ROOT key and use Find to search for the CLSID value which in this example is {EE09B103-97E0-11CF-978F-00A02463E06F} and again make sure Look at has only Key checked then press Find or Find Next.
If the key is found expand and locate the InprocServer32 key in it you will find the location of DLL in the (Default) REG_SZ value. In this example that is C:\Windows\System32\scrrun.dll (this will be different depending on installation location and OS)
What about decompiling?
There's a lot of assumption in the comments about the compiler used to compile the DLL (mainly .NET), but the best way to check is to use one of the many programs out there in the public domain designed for this purpose.
There is a specific question on SO that deals with this;
Answer by #simon-mᶜkenzie to Identifying the origin of a DLL

Microsoft.Office.Interop.Word library is giving Null Reference Exception when I am refrencing Missing Value in ASP.Net

Application msWord = new Microsoft.Office.Interop.Word.Application();
Document doc;
object objMiss = System.Reflection.Missing.Value;
object endofdoc = "\\endofdoc";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// add blank documnet in word application
doc = msWord.Documents.Add(ref objMiss, ref objMiss, ref objMiss, ref objMiss);
Microsoft.Office.Interop.Word.Paragraph para1;
// add paragraph with document
para1 = doc.Content.Paragraphs.Add(ref objMiss);
}
}
When I am assigning to para1, it is giving error -
Object reference not set to an instance of an object.
On my local machine it is working fine. But on Remote it is giving errors.
Note- MS Office is installed on server.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. You can read more about that in the Considerations for server-side Automation of Office article.
Consider using the Open XML SDK if you deal only with opel XML file format documents. If you need to work with binary files, look for any third-party components that support the server-side execution.
Instead of Interop (Office COM) you should use OpenXML in your scenario. But mastering OpenXML is quite of a task and most people quickly realize that it pays off to just buy some toolkit which uses it and become productive immediately.
One tool that might fit your needs very well is Docentric Toolkit. It is OpenXML toolkit under the hood (it is licensed 3rd party product). You can create Document Object Model programatically from the scratch. From this point of view it gives you similar results as if using Office COM. You can choose .docx or .pdf output.
It is also very convenient for template-based reporting with output in .docx and .pdf. Our company uses it for several years and we have been developing most of our reports using this toolkit. Report template is designed in Word using special add-in. It is so simple that even some end users are designing reports already. Templates contain visual layout, formatting and placeholders for data.
Once the template is ready, it can be called from any .NET application, where data is prepared in the form of .NET objects (e.g. from database or XML). Final documents are then generated with two lines of code, where templates and data are merged together. Final document is pure .docx document.
Start > Run
"mmc -32" and then add the Component Services snap-in manually
Navigate to Component Services > Computers > My Computer > DCOM Config
Find Microsoft Word 97 – 2003 Document and right click > Properties
Open Identity Tab
Active "The interactive user" instead of the launching user

How to open word documents in asp.net application

I am under the development of a job portal application.
For that I need resume upload functionality.
Now problem is how can I view the uploaded resume?
I am using ASP.NET with VB.
A good example of viewing word documents on a asp.net page can be viewed at http://www.aspsnippets.com/Articles/Display-Word-document-on-web-page-in-ASP.Net.aspx
You can try a third party library called "Doconut", here is a demo which actually shows a resume DOC opened in an asp.net website, similar to your requirements http://try.doconut.com/Ribbon.aspx
This could help anyone else having similar requirements.
Uploading document must have specific path.So try:
Dim objFile as System.IO.File
Dim sReader as System.IO.StreamReader
sReader = objFile.OpenText(“YourUploadedFilePAth”)
I am sure you can find much on this topic via Google as this is a consistently recurring topic
. Here are a few options:
Opening/Editing of Word Documents via ActiveX Controls - Word/Excel ActiveX Controls in ASP.NET
Via Office Object Model (basically a wrapper around COM Objects) - Automating Applications Using the Office Object Model
Via 3rd Party Libraries e.g. NetOffice (netoffice.codeplex.com)
You may use:
Dim filePath As String = "C:\Attachments\fileName.xls" -- any file format
System.Diagnostics.Process.Start(filePath)

ASP.NET unit testing Windows7/IIS7

Spent several hours today trying to write some unit tests against an ASP.NET project. It's Visual Studio 2010.
Using Windows 7 Enterprise with IIS7.
Steps I took were:
Added a new test project to the solution
Opened a class file as part of the web site (Member.vb)
Right clicked within the class file and "Generate unit tests"
Select the methods I wish to generate stubs for, choose to add to my test project, click OK
Open up the generated MemberTest.vb file in the test project, click within one of the generated tests, click "Run tests in curent context"
When following these precise steps on my Windows XP Professional with IIS6 machine it works fine.
However on the Windows 7 Enterprise machine on IIS7 I get:
The URL specified ('http://localhost/MyProject') does not
correspond to a valid directory. Tests configured to run in ASP.NET in
IIS require a valid directory to exist for the URL. The URL may be
invalid or may not point to a valid Web application.
So what's going on, I can confirm I can browse to http://localhost/MyProject and it displays perfectly.
I feel sure I'm missing some sort of config in Windows/IIS but I'm really at a loss.
Generated test method:
<TestMethod(), _
HostType("ASP.NET"), _
UrlToTest("http://localhost/MyProject")> _
Public Sub MyMethodTest()
Dim target As Member_Accessor = New Member_Accessor() ' TODO: Initialize to an appropriate value
Dim CurrentVal As Short = 0 ' TODO: Initialize to an appropriate value
Dim expected As Short = 0 ' TODO: Initialize to an appropriate value
Dim actual As Short
actual = target.MyMethod(CurrentVal)
Assert.AreEqual(expected, actual)
Assert.Inconclusive("Verify the correctness of this test method.")
End Sub
(Cross-posted at ASP.NET Forums)
This could be a permissions issue.
If you're using the default directory (C:\users\\Documents\Visual Studio 2010\Projects), the app identity pool does not have permissions there. You'd have to create a project in something like C:\webs and make sure app pool identity has permission to the folder.
Refer to Rick Anderson's blog post at http://blogs.msdn.com/b/rickandy/archive/2011/04/22/test-you-asp-net-mvc-or-webforms-application-on-iis-7-in-30-seconds.aspx and see if that helps.
If you have not done unit testing before, I would really recommend that you start by just testing the functionality of your classes as cleanly as possible. Try to break you you functionality into small pieces that can be tested individually without and dependencies to the web context.
Have a look at this question for an idea about What is unit testing
Here is an MSDN Magazine article about testing
You can also have a look at this Blog. The examples are using NUnit but the principal is the same if you are using MSTest.
I can also recommend Roy Osheroves Book Art of unit testing
In you case if the Member class does not have dependencies to web context you don't need the IIS and could instead just do something like this:
<TestMethod()> _
Public Sub MyMethodTest()
Dim target = New Member()
Dim CurrentVal As Short = 0 ' TODO: Initialize to an appropriate value
Dim expected As Short = 0 ' TODO: Initialize to an appropriate value
Dim actual As Short
actual = member.MyMethod(CurrentVal)
Assert.AreEqual(expected, actual)
End Sub
I ran into the same problem today. After some research, I found this thread which suggested I check my event log. Upon doing that, I discovered numerous errors similar to the following:
(QTAgent32.exe, PID 12348, Thread 61) WebSites.GetWebServer: failed to
create AspNetHelper:
Microsoft.VisualStudio.Enterprise.Common.AspNetHelperException: The
website metabase contains unexpected information or you do not have
permission to access the metabase. You must be a member of the
Administrators group on the local computer to access the IIS metabase.
Therefore, you cannot create or open a local IIS Web site. If you
have Read, Write, and Modify Permissions for the folder where the
files are located, you can create a file system web site that points
to the folder in order to proceed. --->
System.Runtime.InteropServices.COMException: Unknown error
(0x80005000)
That lead me to this blog post which seems to have resolved the issue.
I just needed to go to "Turn Windows features on or off" and add IIS 6 Management Compatibility and all four subcomponents. I'm running Windows 7 Home Premium which doesn't have the Windows Authentication option, but that didn't seem to be an issue. Give it a shot and see if that resolves the issue for you.
You may need to enable "Use IIS" in the project properties, then click "Create Virtual Directory". Do you have IIS Express installed?

simple vb.net database program

Over 6 years ago I did visual basic programming. I used VB6 for an editor. I did it for a semester in college, and I didnt make a good grade. Since then I have been doing other things in life. However I was asked at work to create a web application. I am creating my application in vb.net 2003. I began desigining the interface of the web form. I have 5 forms, all of them need to connect to a database which I already have prepared. I created the database in MS Access. If I can get one of the forms to look at the database, I think I can get the rest of them to do it. I have tried using beginner tutorials online and I am not finding anything thats helpful. The closest tutorial I have found that could atleast give me an idea of what to do, the code doesnt work, I did everything to the 'T'. http://www.startvbdotnet.com/ado/msaccess.aspx
Is there anyone out there that can help me?
What you are looking for to access Microsoft Accesss Databases (MDB) is the Microsoft JET Client. If you are using a Visual Studio here is the VB for simple access. You can query the database file with SQL.
Outside class
Imports System.Data.OleDb
Imports System.Data
Inside class, to access the database
Dim cn As OleDbConnection
Dim db As OleDbDataAdapter
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder\file.mdb;")
cn.Open()
db = New OleDbDataAdapter("select * from Table1", cn)
Dim ds As New DataSet()
db.Fill(ds)
For Each row As DataRow In ds.Tables(0).Rows
me.txtRow1.text = row("Row1")
me.txtRow2.text = row("Row2")
me.txtRow3.text = row("Row3")
Next
cn.Close()
cn.Dispose()
cn = Nothing
For more information go to, http://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine . Hope it helps!
A 'low barrier to entry' of using an Access DB with VB.Net would be to import the ADODB COM library. Since you've done VB6 before, you should be familiar with the "classic" ADO syntax.
I'm using it right now with a small VB.Net 2008 app and it works perfectly fine. No need to deal with data connections, adapters, fill methods, data sets, or data tables.

Resources