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.
Related
I have a similar problem, VB.Net - Program can't Edit HKEY_Local_Machine registry entry, that was listed, but the fix did not work for me. I am using Visual Studio 2017. I am trying to create a portable app that will work in Windows 7 Professional and Windows 10 Professional. The idea is to reset the last logged on person to either Blank or a different user. My colleagues and I have to logged into member computers with an elevated account to work on them, but the member does not pay attention and causes our account to get locked out. we are not allowed to use group policy to correct this problem, so I am trying to do it with my app. I can make changes via regedit, vbs and batch files, but I cannot seem to get my program in VB2017 to work. I took off the preferred 32bit checkbox and tried running it as an administrator or a different user with administrative rights. I get the same error . . . cannot write to the registry (HKEY_Local_Machine registry). Below is my code. Any help would be appreciated.
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
Dim regVersion64 As Microsoft.Win32.RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _
(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64).
OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI")
If chkbClearEverything.Checked = True Then
regVersion64.SetValue("LastLoggedOnDisplayName", "")
regVersion64.SetValue("LastLoggedOnSAMUser", "")
regVersion64.SetValue("LastLoggedOnUser", "")
Else
tbd1 = TBLogon.Text
tbs1 = TBsam.Text
tbu1 = TBllu.Text
regVersion64.SetValue("LastLoggedOnDisplayName", tbd1)
regVersion64.SetValue("LastLoggedOnSAMUser", tbs1)
regVersion64.SetValue("LastLoggedOnUser", tbu1)
End If
Dim rvLastLoggedOnDisplayName As String = regVersion64.GetValue("LastLoggedOnDisplayName")
Dim rvLastLoggedOnSANuser As String = regVersion64.GetValue("LastLoggedOnSAMUser")
Dim rvLastLoggedOnUser As String = regVersion64.GetValue("LastLoggedOnUser")
If Not rvLastLoggedOnDisplayName = "" Then
TBLogon.Text = rvLastLoggedOnDisplayName
tbd1 = rvLastLoggedOnDisplayName
End If
If Not rvLastLoggedOnSANuser = "" Then
TBsam.Text = rvLastLoggedOnSANuser
tbs1 = rvLastLoggedOnSANuser
End If
If Not rvLastLoggedOnUser = "" Then
TBllu.Text = rvLastLoggedOnUser
tbu1 = rvLastLoggedOnUser
End If
regVersion64.Close()
End Sub
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
I am writing a small program in which user will select set of file (mostly .CSV) files and my program will search through them and find required data.
It's working for up to 300 files, but after that its not working. It's giving me an error:
InvalidOperationExceprion was Unhandaled
Too Many files are selected. Select Fewer files and try again.
What should i do?
Like Eric Walker said, open file dialog works with 1,000's and 1,000's of files, there is no reason why it would stop at 300.
The best way to loop though files/folders to get info is to use the .GetFiles() method
Dim OFD As New FolderBrowserDialog
If OFD.ShowDialog = DialogResult.OK Then
For Each f In Directory.GetFiles(OFD.SelectedPath)
If Path.GetExtension(f) = ".txt" Path.GetExtension(f) = ".csv" Then
Dim reader As String() = File.ReadAllLines(f)
For each line as String in reader
DoSomethingAwesome(line)
Next
End If
Next
End If
This will cycle through every file in a certain Directory.
Now if you would like to cycle through every file in a file dialog, then you would use this.
Dim OFD As New OpenFileDialog()
OFD.Multiselect = True
If OFD.ShowDialog = DialogResult.OK Then
For Each f In OFD.FileNames
If Path.GetExtension(f) = ".txt" Path.GetExtension(f) = ".csv" Then
Dim reader As String() = File.ReadAllLines(f)
For Each line As String In reader
DoSomethingAwesome(line)
Next
End If
Next
End If
Give one of these a try depending on your preference.
As a side note, for future posts - please post your attempted code or more details on what you are trying to accomplish and where you are having trouble. Frankly, Im surprised you weren't downvoted (very surprised, people on SO can be ruthless). Just a friendly tip.
I am trying to write a file listing custom class in VB.net 2010 express on a Win7 64 bit machine. I installed VB.net express using an account that has administrator rights on both the machine and the network it belongs to. I should be able to access any file on the machine and from Windows Explorer, I can. I have been stopped cold by a “System.UnauthorizedAccessException”.
I have tried changing the manifest file. Although that should not be needed since the account already has full permissions. It has not worked. Below is a fragment of the offending code.
I am beginning to wonder if it is possible read the files on a drive using managed code. I can revert to the VBA class that in capsules ancient Win32 API calls that I wrote years ago but that violates the purpose of this exercise. Any suggestions would be appreciated.
Private Sub sLoadCatalog(ByVal strPath As String, ByVal intParentID As Integer)
'Get the file list
Dim strsearchPattern As String = "*"
Dim fp As New FileIOPermission(FileIOPermissionAccess.PathDiscovery _
Or FileIOPermissionAccess.Read, strPath)
Try
'fp.Demand()
fp.Assert()
Dim dirInfo As DirectoryInfo = New DirectoryInfo(strPath)
Dim FileList() As FileInfo = dirInfo.GetFiles()
If FileList.Length > 0 Then
… Loop through the file list and do something exciting
End If
Dim dirFolder() As DirectoryInfo = dirInfo.GetDirectories
If dirFolder.Length > 0 Then
… Loop through the folder list and do something exciting
sLoadCatalog(strfolder, intLastID)
Else
Exit Sub
End If
Catch e As SecurityException
MessageBox.Show("Security Cannot access folder " & strPath)
Catch k As UnauthorizedAccessException
MessageBox.Show("Unauthorized Cannot access folder " & strPath)
End Try
First of all Im new to vb 2010 and so far have enjoyed what I have been able to do with it. That being said I have run into an issue with my current project.
Basically I have created a timer and all works well on that part. My issue lies in that my timer loads a .png for each minute/second and I was linking the images like so:
Picturebox1.Image = Image.Fromfile("C:\timer\images\" & minutes.text & ".png")
Picturebox2.Image = Image.Fromfile("C:\timer\images\" & seconds.text & ".png")
So running this on another pc rendered that bit of code useless as that computer did not have those files locally and the program would end in an error as it could not find the .png files.
I did a bit of searching online and found a few sites and video tutorials how to read from the resource file. But in doing so I have been unable to make it function properly.
So this is what I found here:
Picturebox1.image = My.Resources.minutes.text
Picturebox2.image = My.Resources.seconds.text
I know this bit of code is wrong as I'm now getting 2 errors in vb 2010. The only way I have managed to make this work is to specify the file name. But what I'm wanting to do is use whats in "minutes.text" and "seconds.text" to specify the file name.
Is there a way around this? or do I have to use a bunch of if statements to do this?
example:
If minutes.text = 1 Then
picturebox1 = My.Resource._1
End If
If seconds.text = 12 Then
Picturebox2 = My.Resource._12
End If
I would hate having to do a bunch of if statements if there is a simple fix. So I've come here for help.
i think you are looking for this:
Dim currentMin as string = "_" & minutes.text ' it would look something like this: _1
picturebox1.Image = CType(My.Resources.ResourceManager.GetObject(currentMin), Image)
Dim currentSec as string = "_" & seconds.text
picturebox2.Image = CType(My.Resources.ResourceManager.GetObject(currentSec), Image)
I have tried this form, and it is functional
Picturebox1.Image = Image.FromHbitmap(My.Resources.imagename.GetHbitmap())