I'm trying to set up a new SharePoint production server and getting an error creating an Open XML 2.5 document - vb.net

I have a SharePoint application written in Visual Basic that works fine and creates Word Documents using Open XML 2.5 on my development machine. We recently set up a new Production server and I published the .wsp file and deployed it on the new server. The application all works fine except the code that generates reports in Word format. It fails on the following line of code.
Dim wpd As WordprocessingDocument = WordprocessingDocument.Create(MemStream, WordprocessingDocumentType.Document, True)
This is what the code looks like in the function that is failing.
''' \<summary\>
'''
''' \</summary\>
''' \<param name="MemStream"\>\</param\>
''' \<returns\>\</returns\>
Public Function WPDCreateFromStream(MemStream As MemoryStream) As WordprocessingDocument
Try
Dim wpd As WordprocessingDocument = WordprocessingDocument.Create(MemStream, WordprocessingDocumentType.Document, True)
Dim MainPart As MainDocumentPart = wpd.AddMainDocumentPart()
MainPart.Document = New Document()
Dim DocBody As New Body()
Return wpd
Catch ex As Exception
WriteErrorToEventLog("OpenXML", "WPDCreateFromStream", "", ex)
Return Nothing
End Try
End Function
Here is the exception detail I get when trying to make the WordProcessingDocument.Create call above.
ERROR: Source: OpenXML Routine: WPDCreateFromStream User:
Message: The type initializer for 'MS.Utility.EventTrace' threw an exception.
StackTrace: at MS.Utility.EventTrace.EasyTraceEvent(Keyword keywords, Event eventID)
at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming)
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.CreateCore(Stream stream)
at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Create(Stream stream, WordprocessingDocumentType type, Boolean autoSave)
at FIS.SP.PSTARProjectTracker.PSTAR.Core.BusinessLogic.OpenXML.WPDCreateFromStream(MemoryStream MemStream)
Source: WindowsBase
Data: System.Collections.ListDictionaryInternal
InnerException: System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, Object defaultValue)
at MS.Utility.EventTrace.IsClassicETWRegistryEnabled()
at MS.Utility.EventTrace..cctor()
The Zone of the assembly that failed was:
MyComputer
ToString: System.TypeInitializationException: The type initializer for 'MS.Utility.EventTrace' threw an exception. ---> System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, Object defaultValue)
at MS.Utility.EventTrace.IsClassicETWRegistryEnabled()
at MS.Utility.EventTrace..cctor()
--- End of inner exception stack trace ---
at MS.Utility.EventTrace.EasyTraceEvent(Keyword keywords, Event eventID)
at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming)
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.CreateCore(Stream stream)
at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Create(Stream stream, WordprocessingDocumentType type, Boolean autoSave)
at FIS.SP.PSTARProjectTracker.PSTAR.Core.BusinessLogic.OpenXML.WPDCreateFromStream(MemoryStream MemStream)
TargetSite: Void EasyTraceEvent(Keyword, Event)
I know this is not an issue with the code as the same code works in development. I assume it has to do with permissions, or getting the DocumentFormat.OpenXML.dll installed / registered correctly on the new server, but I've had no luck searching for a solution.
I tried installing OpenXML and the Productivity tool on the server. The productivity tool works and can open a word document, but the Application has the same issue.
If anyone has run into this and can point me to a solution, I would appreciate it.
The MemoryStream is created and passed in to be used by this function. The WordProcessingDocument is returned to the calling function. I could explicitly call ByVal, but in this case it would not change anything.
I am creating a new document, that is why it is coded using WordProcessingDocument.Create
Remember, this code all functions perfectly on the development SharePoint server. It has been used heavily for about a year. I'm just trying to get this to work on a new production server we recently stood up. I have to believe this is related to some permission issue, or a component that is not installed or registered correctly. For Open XML, I believe there is just the one DLL (DocumentFormat.OpenXML.DLL) and it does not register. It is on the server from installing the .wsp package. I also tried installing Open XML 2.5 on the server along with the productivity tool and they all work fine.
The more I think about it, it just feels like a permission issue.

Related

Upload file to share point server from external application

My client has requested to upload files to his share point server from and external application. So I have designed a windows application and used Microsoft.sharepoint.dll supplied by client and used the following code for upload.
Public Function UploadFileToSharepoint(ByVal pstrSourceFilePath As String, ByVal pstrTargeSPURL As String) As Boolean
If Not File.Exists(pstrSourceFilePath) Then
Throw New ArgumentException(String.Format("{0} does not exist", pstrSourceFilePath), "srcUrl")
End If
Dim site As SPWeb = New SPSite(pstrTargeSPURL).OpenWeb()
Dim fStream As FileStream = File.OpenRead(pstrSourceFilePath)
Dim contents(CInt(fStream.Length)) As Byte
fStream.Read(contents, 0, CInt(fStream.Length))
fStream.Close()
EnsureParentFolder(site, pstrTargeSPURL)
site.Files.Add(pstrTargeSPURL, contents)
Return True
End Function
I am able to compile it but while running the application I am getting an error like "Could not load or found an assembly "Microsoft.Sharepoint.Library.dll".
My question: Is it possible to develop an application to create a folder structure and upload the file to share point server without having the share point installed on the machine but having only the share point dll's?
Suggest me a way to carry out this kind of development. In future my application will run on a machine where share point server is not installed.
Rupesh
Yes, you can do that using Client Object Model - just reference Microsoft.SharePoint.Client in your project. Here's how to do it in C#, VB.net shouldn't be much different.
ClientContext context = new ClientContext("http://mydomain");
Web web = context.Web;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(#"C:\MyFile.docx");
newFile.Url = "MyFile.docx";
List docs = web.Lists.GetByTitle("Documents");
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
context.Load(uploadFile);
context.ExecuteQuery();
You should look into using the SharePoint Client-Side Object model (CSOM). That will allow you to interact with SharePoint from a client.
More info here --> http://msdn.microsoft.com/en-us/library/office/ee535451(v=office.14).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

QBFC WCF Service Error

I have a new blank Wcf Service in vs.net 2013 express. I have added the reference to the qbfc12.dll and did the import Imports QBFC12Lib. I run the blank wcf service and it works fine. I then add one line of code and it breaks and gives me a error.
Function that works fine:
Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
Return String.Format("You entered: {0}", value)
End Function
Function that gives exception(One line of code added only):
Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
Dim SessionManager As New QBSessionManager
Return String.Format("You entered: {0}", value)
End Function
I get the following exception on that line:
An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code
Additional information: Retrieving the COM class factory for component with CLSID {C693D8F1-180B-4F82-B735-8F511B566718} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Can anyone please help me? I have a wcf server written on my laptop, that runs perfect. I am only trying to move it to my production server, but does not work. So removed all the code down to this one line of code that is giving the issue, but it all worked fine on my laptop.
The QBFC12 installer needs to be run on the machine your application is executing from. It is available for download in the link below. You have to sign up to download the installer, but there's no cost and you don't even have to verify your email.
Page with all installers:
https://developer.intuit.com/docs/0200_quickbooks_desktop/0400_tools/quickbooks_desktop/download_the_sdk
Installer in question:
QBFC12_Installer (Version 12.0.0.29)
https://developer.intuit.com/Downloads/Restricted?filename=qbfc12_0installer.exe

how to avoid/remove invalidcastexception

Within a SSIS 05 (VB.NET) script, an interesting exception occured. The development environment does not show any errors concerning the script.
Following error message is shown within the script component in the ETL process.
Unable To Cast COM Object Of Type 'System.__ComObject' To Class Type 'System.Data.SqlClient.SqlConnection
A connection manager is in use.
Dim connMgr As IDTSConnectionManager90
Here the applied CType command.
Public Overrides Sub AcquireConnections(ByVal Transaction As Object)
connMgr = Me.Connections.Connection
sqlConn = CType(connMgr.AcquireConnection(Nothing), SqlConnection)
End Sub
Any experience how to avoid this issue? Any help will be appreciated.
btw The 2012 version (in C#) works without troubles. The 2005 version was manually downgraded/rewritten.
public override void AcquireConnections(object Transaction)
{
connMgr = this.Connections.Connection;
sqlConn = (SqlConnection)connMgr.AcquireConnection(null);
}
Addendum:
That does not work.
sqlConn = New SqlConnection(connMgr.ConnectionString)
The cast problem was an issue even without a cast (see snippet above with new keyword).
Hence, statements were rewritten.
The main point --- no problem furthermore concerning the old issue.
oleDbConn = New OleDb.OleDbConnection(connMgr.ConnectionString)

Issue with SQL Server FileStream

We are currently reviewing an issue we have on one of our live environments where OpenFileStream (private method inside SqlFileStream C# class)
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the path specified at System.Data.SqlTypes.SqlFileStream.OpenSqlFileStream(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize)at System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize)at System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access)
We have this working on another environment with no issues. The code we are using to call is as follows:
using (SqlCommand command = new SqlCommand(insertFileSql, conn, transaction))
{
string path = null;
byte[] context = null;
using (SqlDataReader reader = command.ExecuteReader())
{
reader.Read();
path = reader.GetString(reader.GetOrdinal("PathName"));
fileID = reader.GetGuid(reader.GetOrdinal("FileId"));
context = (byte[])reader[reader.GetOrdinal("Context")];
}
richTextBox1.AppendText(
string.Format("Path: {0}, FileID:{1}, content: {2}", path, fileID, Convert.ToString(context)));
using (SqlFileStream strm = new SqlFileStream(path, context, FileAccess.ReadWrite))
{
// copy the user file to the Filestream
inputFileStream.CopyTo(strm);
}
We've looked at ports/firewalls and even got to the point of seeing it is NtCreateFile failing inside the .Net Source code (with a value of 3221225530) but I can't find documentation on what that value or the value returned form IOStatusBlock which is one of the return parameters.
\\v02-A60EC2F8-2B24-11DF-9CC3-AF2E56D89593\dbFileStore\dbo\tblFile\DataFile\AC50B769-B6F8-43AA-B266-E4E837D78BA0\VolumeHint-HarddiskDmVolumes\\SQLData
Is there anything anybody else could suggest to look at, me and my team have been looking at this for best part of two days.
Cheers,
J
Though so much time has passed, we with SQL Server 2012 had this problem with ReadWrite. No problem with Read, no problem with Write, but only with ReadWrite.
Looks like something happens during install/uninstall of SQL Server updates - a registry setting gets accidently removed by setup. Readding it with .reg file:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\FsctlAllowlist]
"FSCTL_SQL_FILESTREAM_FETCH_OLD_CONTENT"=dword:00092560
Worked out that it was Veritas Storage Foundation which wasn't working with SQL FileStream, seems there is a bit of issue with VSF when performing Windows API calls.

Trouble creating the DNN Survey Module from source code

My boss has asked me to set up DotNetNuke's Survey Module and make a few custom changes to it for a client. But I'm having trouble just getting the bare-bones code to run properly!
Here's what I've done so far:
Downloaded both the source & install folders from
http://dnnsurvey.codeplex.com/releases/view/65186
Created a new VB Web Application Project
Took out all the default pages
Copied the Survey source code into the VB Web Application Project in exactly the same structure
Made a batch script that creates an installation folder identical to DNN's install folder (double-checked by running a folder-diff on it, and all files/folders were identical)
Zipped up my installation folder using 7-zip
The source code compiles perfectly. But even though the files/folders are identical, DNN's zipped package will work properly on my DNN site, and my own zipped package will fail with this famous error message:
Error: Survey is currently unavailable.
DotNetNuke.Services.Exceptions.ModuleLoadException: Could not load type 'DotNetNuke.Modules.Survey.survey'. ---> System.Web.HttpParseException: Could not load type 'DotNetNuke.Modules.Survey.survey'. ---> System.Web.HttpParseException: Could not load type 'DotNetNuke.Modules.Survey.survey'. ---> System.Web.HttpException: Could not load type 'DotNetNuke.Modules.Survey.survey'. at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError) at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly) at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData) --- End of inner exception stack trace --- at System.Web.UI.TemplateParser.ProcessException(Exception ex) at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding) at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding) --- End of inner exception stack trace --- at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding) at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath) at System.Web.UI.TemplateParser.ParseInternal() at System.Web.UI.TemplateParser.Parse() at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType() at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath) at DotNetNuke.UI.ControlUtilities.LoadControl[T](TemplateControl containerControl, String ControlSrc) at DotNetNuke.UI.Modules.ModuleHost.LoadModuleControl() --- End of inner exception stack trace ---
I've already asked about this on the DNN forums, but they don't have much to say about it :( So, I thought I'd try StackOverflow as well.
Does anybody have any idea what the problem could be? Thanks very much in advance!
If you want to create package, correctly, you have to first install the module that you have in your dnn instance. Once you are done with that, you did the right job till step4. After step 4 I generally do following:
Go to project properties, and point the bin directory path to parent dnn installation's bin directory
Add reference of dotentnuke.dll and microsoft data acecss application blogs dll
Rebuild the project
Once you can correctly compile the app, you are ready to customize it.
Always use dnn's module create wizard to create package. it is easier and error free way of packaging and delivering the modules.
let me know if you need any other help
I ended up solving this one on my own. These are the steps I took:
Removed all Namespace DotNetNuke.Modules.Survey declaractions
Deleted the ascx, ascx.vb, and designer files for survey, Settings,
and EditSurvey
Created new, empty ones with those names (but used "Survey" instead
of "survey")
Copied/pasted the ascx code into each ascx file (and changed
DotNetNuke.Modules.survey to DotNetNuke.Modules.Survey)
Did a build
Copied/pasted the ascx.vb code into each ascx.vb file (and removed
the Namespace declarations in these files)
Did a build, which was 100% successful this time
Bizarre way to solve the problem, but it worked. :3