Extract file using SevenZip - vb.net

I'm trying to add a file unzipper to my application, so I googled a little and stumbled on the sevenzipsharp library that is able to extract the most common archive formats.
So I for testing I created a simple application with a windows form.
So the entered data is the file location C:\Users\jeee\Desktop\CriticalSubPrintout.rar and the extract location C:\Users\jeee\Desktop\Test Extract
I added some code, without any documentation.. not my strong side apparently..
Imports SevenZip
Public Class Archiver
Private Sub btnExtractArchive_Click(sender As Object, e As EventArgs) Handles btnExtractArchive.Click
Dim Extractor As New SevenZipExtractor(tbExtractFile.Text)
Extractor.ExtractArchive(tbExtractPath.Text)
End Sub
End Class
This causes an error when I try and run the code
Can anyone provide a sample code, or a link to a good example how-to-use SevenZipSharp? Because I searched and can't find any VB.NET samples.
Or maybe just help me figure out what I need to do.
Thanks.

You need to call SevenZipBase.SetLibraryPath with the path to 7z.dll, and make sure that you are using the correct version for your application (32- or 64-bit). e.g.
SevenZipBase.SetLibraryPath("C:\Dev\7z.dll")
Dim Extractor As New SevenZipExtractor(tbExtractFile.Text)
Extractor.ExtractArchive(tbExtractPath.Text)

Related

How do I find and open the most recent txt file within a subdirectory structure using vb.net

Using vb.net I am writing a standalone application that needs to read a value from the very latest text file written to a random subdirectory from a known directory. I need this to run on a scheduled basis so I am using the vb timer.
Despite searching the web for some time I can't seem to find any code to perform this relatively simple task without visual studio failing to compile all the examples I've tried. Surely this is quite a simple task?
Also what would be the most efficient way of doing this?
Private Sub tmrLoop_Tick(sender As Object, e As EventArgs) Handles tmrLoop.Tick
For Each TXTFile As System.IO.FileInfo In New System.IO.DirectoryInfo(Server.MapPath("\\10.179.221.125\cmsdata\GNH3D\TDD\TDD_waveradar\H1d3\"))
.GetFileSystemInfos("*.txt", System.IO.SearchOption.AllDirectories)
.OrderByDescending(Function(f) f.LastWriteTimeUTC)
.Skip(PageSize * Page)
.Take(PageSize)
MsgBox(TXTFile)
Next
End Sub
The above code doesn't like the Server.MapPath part

How can I check if a string given is a real word?

I am making a program that solves anagrams in Visual Basic. How can I check if a string given by the anagram solver is a real word? I know I will have to access some sort of dictionary but I have no idea how to do this?
I need a function that checks the word to return a true/false boolean value. Is this possible?
I'm using Visual Basic in Microsoft's VS2015.
Hunspell is pretty easy to use.
Install the .net-library through Nuget (open your project in Visual Studio, then > Extras > Nuget-Package-Manager -> Console, type Install-Package NHunspell)
Download the .aiff and .dic files, see the dictionaries link on the Hunspell project page. Include these files in your project or use absolute paths.
Sample Code:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Using h As New NHunspell.Hunspell(
"...path ...\en_US.aff",
"...path ...\en_US.dic")
Me.TextBox1.BackColor = If(h.Spell(Me.TextBox1.Text),
Color.PaleGreen, Color.PeachPuff)
End Using
End Sub
Hunspell
.net library NHunspell
NHunspell C# Code Samples
If your are using WPF then checking if a word in a textbox can be done simply by checking if it has a spelling error.
Public Function WordOk(Word As String) As Boolean
return TextBox1.GetNextSpellingErrorCharacterIndex(0, Windows.Documents.LogicalDirection.Forward) < 0
End Function
If you are using windows forms then you can create a "User Control (WPF)" to do the same thing, though it is a bit tricky to explain how to do that here.
(There may be a better test than the one I showed though.. I'm not overly familiar with WPF)

How do I use My.Computer.FileSystem.CurrentDirectory with My.Computer.Network.DownloadFile?

I am trying to use it like this:
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
My.Computer.Network.DownloadFile(
"http://magicalexample.com/multi.zip", "My.Computer.FileSystem.CurrentDirectory\multi.zip")
Process.Start("cmd", "/k jar xf multi.zip")
MsgBox("Done.")
End Sub
End Class
(note: I screwed up the formatting, it's right in VB, don't worry lol)
When I try to use the update button, it tells me that destinationFileName needs to include a file name. Do they not play well together or what?
My.Computer.FileSystem.CourrentDirectory is a variable and isn't going to be magically parsed into your string. You need to concatenate the variable with the file location:
My.Computer.Network.DownloadFile("http://magicalexample.com/multi.zip", My.Computer.FileSystem.CurrentDirectory & "\multi.zip")
Or use the Path.Combine() method to merge the directory plus filename:
My.Computer.Network.DownloadFile("http://magicalexample.com/multi.zip", Path.Combine(My.Computer.FileSystem.CurrentDirectory, "multi.zip"))
Note that your examples aren't working for various reasons. They need the http:// in front of them AND the file must exist at the source (cannot be a 404 Not Found Error). Also, the extra semi colon in the comments you posted seems to indicate that it wouldn't even be compiling so you might be running a prior version. I created a new project and as an example ran this code which worked to download the google logo from the main page.
My.Computer.Network.DownloadFile("https://www.google.com/images/srpr/logo11w.png", Path.Combine(My.Computer.FileSystem.CurrentDirectory, "logo.png"))

How to read an Atom Feed in VB.Net

I have searched and searched and searched enough until my Head aches! What I am trying to do is take an ATOM feed from here: National Weather Service Alerts and incorporate it into my program, however, I don't even KNOW where to begin :( What I want to do eventually is download the Atom feed and place it in a scrolling label. I don't want to parse it pulling out sections or anything. Just want to display the NWS alert for my area. I don't expect anyone to just write out the code or anything, but any help pointing me in the right direction for programming it simply and painlessly for an intermediate vb programmer would be greatly appreciated. Please Help!
Here is a code sample that should work for your case. Assuming you already downloaded your Atom feed and saved it to your disk. If not, you may need a slight modification:
Imports System.Xml
Imports System.ServiceModel.Syndication
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim messageList As New Generic.List(Of String)
Using feedReader = XmlReader.Create("X:\vi.php.webintents")
Dim feedContent = SyndicationFeed.Load(feedReader)
If feedContent Is Nothing Then Return
For Each item As Object In feedContent.Items
messageList.Add(Convert.ToString(item.Title.Text))
Next
End Using
lbl_warnings.Text = String.Join(vbNewLine & vbNewLine, messageList)
End Sub
End Class
Replace "X:\vi.php.webintents" with your file location.
For System.ServiceModel.Syndication to be available, you need to add System.ServiceModel.dll to your references (.NET 4.0). For .NET 3.5 you would use System.ServiceModel.Web.dll
I used this answer as a base for SyndicationFeed usage in this example.

How to update DotNetNuke's HTML module content through code?

I'm working on a DNN module which needs to be able to update the HTML content of existing HTML modules. Does anyone know how to do this through code?
I've determined the content gets stored in the HtmlText table, but I'd rather not write directly to the table. Does anyone knows how to accomplish this using the DNN API?
Thanks in advance.
Here's the solution I found, with the help of mika & bdukes :
''' <summary>Add HTML contest to an existing HTML module.</summary>
Private Sub AddHTML(ByVal ModuleID As Integer, ByVal HTML As String)
Try
Dim oHTML As New DotNetNuke.Modules.Html.SqlDataProvider
'-- i'm not sure what "history" should be set for in the method below.
'-- i suspect it means "version history", which 5 seems to be the default based on what i've read.
oHTML.AddHtmlText(ModuleID, HTML, 1, 1, UserId, 5)
Catch ex As Exception
'failure
End Try
End Sub
Notes:
This routine adds HTML content to a
just-created HTML/Text module, so
checking for existing HTML content
isn't necessary.
I'm a little fuzzy about the 3rd and
6th parameters (StateID & History),
although it seems to be
working correctly. If anyone knows
more about them, I'd like to
know the correct way to set these parameters.
Version 5.2 of the HTML module (which started being distributed with DNN 5.2) and above are compiled, with a reference in the website's /bin/ directory. You can make a reference to DotNetNuke.Modules.Html.dll in your project and use the methods on HtmlTextController to make the updates (as #mika mentions). However, because of changes to the HTML module over time, you'll need to make sure that you re-check your module (and potentially update your integration) every time you update DNN.
You can take a look at our free Engage: F3 module to see how we've addressed differences in the code bases of various versions.
Use Text/HTML module. It is not distributed as a .dll, but you'll find the code in the /App_Code/HTML folder.
HtmlTextController has the methods:
- Public Sub AddHtmlText(ByVal objText As HtmlTextInfo)
- Public Function GetHtmlText(ByVal moduleId As Integer) As HtmlTextInfo
- Public Sub UpdateHtmlText(ByVal objText As HtmlTextInfo)