I have a VB.Net windows forms application which is working fine in windows 7 environment.
Now, I want to upgrade to windows 10. So I have started to test my application in windows 10 server machine.
I am getting an Exception (Exception from HRESULT:0X800A03EC) while saving a dynamically generated file in one of the folders on server.
I have identified the issue is not with the permissions.
'getting exception at this line of code.
xlApp.Workbooks(1).SaveAs(filename , xl.XlFileFormat.xlHtml)
Code for reference:
Private Sub VierwInBrowser(ByVal xlApp As xl.Application)
Dim fileName As String = String.Format("{0}\{1}", "C:\Data", GetUniqueFileName())
Try
xlApp.Workbooks(1).SaveAs(fileName, xl.XlFileFormat.xlHtml)
Catch ex as Exception
Messagebox.Show(ex.Message)
End Try
xlApp.Quit()
xlApp = Nothing
GC.Collect()
browser.Visible = True
browser.Navigate(fileName)
browser.BringToFront()
End Sub
I have identified that the issue is with converting the excel sheet to html page in windows 10.
For this I have found a solution at https://support.microsoft.com/en-in/help/922850/error-message-in-office-when-a-file-is-blocked-by-registry-policy-sett
Related
I have a system that backs up data to a network with certain parameters in place such as:
'If x process is running, do not run the backup'
Because it's connected to a network, users will constantly be on it. The problem I have is that I don't want the data to get moved onto the network if it's in use, plus, the data is unable to move across if someone is using file explorer on the same computer as the program is on.
I would use 'If explorer is running, do not run the backup' but explorer is linked to windows and is always running
If program.Count > 0 Or program2.Count > 0 Then
Try
Msgbox("Process Running")
Catch ex As Exception
End Try
Else
'backup data
End If
Is there a way to try get the program to transfer files, but if fails because the file directory is already open, then do x?
Try this. It should generate an error if you can't lock the file.
Public Function IsFileLocked(file As FileInfo) As Boolean
Dim stream = DirectCast(Nothing, FileStream)
Try
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None)
Catch generatedExceptionName As IOException
'handle the exception your way
Return True
Finally
If stream IsNot Nothing Then
stream.Close()
End If
End Try
Return False
End Function
I have designed a vb.net application which uses OpenFileDialoge to open a picture in PictureBox.
My machine is windows 7 32bit and this is my code:
Dim directoryName As String = Path.GetDirectoryName(Application.ExecutablePath)
Try
Dim dialog As New OpenFileDialog
directoryName = ""
dialog.InitialDirectory = directoryName
dialog.Filter = "Pictures|*.jpg|All files (*.*)|*.*"
dialog.FilterIndex = 1
dialog.RestoreDirectory = True
If dialog.ShowDialog = DialogResult.OK Then
TextBox8.Text = dialog.FileName
PictureBox1.Image = Image.FromFile(TextBox8.Text)
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString)
End Try
everything is good on my machine, but on the client machine who has windows 7 64bit, when he trying to open an image, he got like this Picture:
Also, I tried to change the .Net framwork with different versions but nothing happened, anyone have an idea please?
I just resolved my problem after 5 days of searching and trying time and time again.
I was using MS Acess 2010 database with my program as back end and the solution was to convert it to MS Acess 2003.
I don't know what the relate of that!, but it's solved.
For some reason I can't load this report twice in one program session. I can print it the first time without a problem. The second time I get the error:
CrystalDecisions.Shared.CrystalReportsException: Load report failed.
Here is my code for this segment.
Private Sub Print_Report()
Using CrystalReport As New ReportDocument
CrystalReport.Load("Reports\PrintMe.rpt")
CrystalReport.SetParameterValue("Code", txtCode.Text)
CrystalReport.SetParameterValue("Control", txtControl.Text)
CrystalReport.PrintOptions.PrinterName = DefaultPrinterName()
CrystalReport.PrintToPrinter(1, True, 0, 0)
End Using
End Sub
Private Function DefaultPrinterName() As String
Dim psDefault As New System.Drawing.Printing.PrinterSettings
Try
DefaultPrinterName = psDefault.PrinterName
Catch ex As System.Exception
DefaultPrinterName = ""
Finally
psDefault = Nothing
End Try
End Function
All I can think is that the file isn't being let go at the end of the first print. Am I over looking something simple?
The issues was caused by using Foxit Reader's PDF Printer. I switched to using Adobe Acrobat and the issue is now gone. I'm only using the PDF Printer for printer tests to save paper. I will be using the Export to Disk for anything PDF related.
I have a VB.Net application in which I have a general method to open documents that exist on the local drive using system.diagnostics.process.
Public Shared Function OpenFileWithProcess(ByVal lsFileNameWithPath As String, Optional ByVal lPrintOption As PrintOutputOption = PrintOutputOption.Preview)
Try
Select Case lPrintOption
Case PrintOutputOption.Preview
Dim P As System.Diagnostics.Process
P = Process.Start(lsFileNameWithPath)
If Not P Is Nothing Then
Dim handle As IntPtr = P.Handle
SetForegroundWindow(handle)
End If
Case PrintOutputOption.Print
Dim Proc As New Process
Proc.StartInfo.FileName = lsFileNameWithPath
Proc.StartInfo.UseShellExecute = True
Proc.StartInfo.Verb = "Print"
Proc.Start()
End Select
Catch ex As Exception
If oSQL.Key_Developer Then
Stop
End If
Throw ex
End Try
End Function
On some computers that have Windows8 and OFfice2010, this method will not open an Excel file without Excel being open first. Instead it will error with "Run-Time Error 2147467259 (80004005). An error occurred in sending the command to the application".
If Excel is open prior to the method call, then the file opens just fine.
Some additional environment info:
- VB.NET application compiled to .Net Framework 4
- Application is deployed on Windows 7, 8 and 8.1
I could trap for the error and try to start the process again using the Excel session that hangs open after the error but I'm wondering if someone can tell me or help me figure out what is going on here.
Thank you for your time.
I would really appreciate your help here. My application is as follows,
Operating System: Windows 7 64 Bit OS
Visual Studio: VS 2012
Application: VB.Net running on .Net framework 4
In my application, I have a button which calls my custom method ‘Select_Batch_File()’. Once this button is clicked it supposes to open the ‘OpenFileDialog’ to select particular file. This works fine on my machine with above configuration however; on some of my colleagues machine (with same configuration above) this does not work and fails without any exception. I have collected the thread dump from my colleague’s machine which is as follows,
======================
Log Name: Application
Source: .NET Runtime
Date: 3/18/2013 1:54:19 PM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Description:
Application: Visual AEEMS.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at System.Windows.Forms.FileDialogNative+IFileDialog.Show(IntPtr)
at System.Windows.Forms.FileDialog.RunDialogVista(IntPtr)
at System.Windows.Forms.FileDialog.RunDialog(IntPtr)
at System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)
===============
I followed a solution from MSDN forum wherein users were asked to uncheck the option in visual studio > Tools > Options > Debugging > ‘Suppress JIT optimization on module load (Managed only)’ but had no luck.
Here is my code
Sub Select_Batch_File()
Try
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.AutoUpgradeEnabled = False
Full_Path = "" : file_name = ""
OpenFileDialog.Multiselect = False
Try
<<Here I am getting exception>>
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
EMS_Dir = OpenFileDialog.FileName 'get the path
EMS_Dir = StrReverse(EMS_Dir) 'reverse the string
EMS_Dir = Mid(EMS_Dir, InStr(EMS_Dir, "\"), Len(EMS_Dir)) 'extract from the first slash
EMS_Dir = StrReverse(EMS_Dir) 'reverse it again
'file_name = OpenFileDialog.SafeFileName
file_name = OpenFileDialog.FileName
End If
Catch ex As Exception
Logger.LogInfo(ex) : MsgBox(ex.Message)
End Try
Catch ex As Exception
Logger.LogInfo(ex) : MsgBox(ex.Message)
End Try
End Sub
Please advice.
You will get an exception if you set the AutoUpgradeEnabled property. Don't know why, but there it is.