I am trying to write an program to extract zipped files using vb.net. I am facing a problem - when I try to extract the files, it ask fro replacement agreement, but I need to extract that files without asking for my an agreement.
This is the code I use:
Dim shObj As Object = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"))
Dim outputFolder As String = appPath
Dim inputZip As String = appPath + "\patchFile.zip"
IO.Directory.CreateDirectory(outputFolder)
'Declare the folder where the items will be extracted.
Dim output As Object = shObj.NameSpace((outputFolder))
'Declare the input zip file.
Dim input As Object = shObj.NameSpace((inputZip))
'Extract the items from the zip file.
output.CopyHere((input.Items), 4)
I think you can use the second parameter of CopyHere to respond Yes To All for any dialog box displayed and it should avoid your dialog box.
output.CopyHere((input.Items), 16)
Edit :
And if you still need option 4 to not show progress, you can combine both so it would be 20 instead of 16
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
You can open PDFs in text editors to see the structure of how the PDF is written.
Using VBA I have opened a PDF as a text file and go to extract the text and save it as a string variable in VBA. I want to look through this text to find a specific element; a polyline (called sTreamTrain) and get the vertices of the polyline by using the InStr function.
When i add more vertices to the polyline I cannot seem to extract the text string of the pdf. I get the error 'Run time error 62' which I do not understand what it means or what about the PDF has changed to now have this error.
Attached (via the link) is a PDF that I can read (Document 15) and a PDF I cannot read (Document 16). I have checked in excel so see that the vertices are present in both files. Also there is a copy of my VBA script as a notepad document and also my excel file (but it is difficult to find in my excel file - the script is "Module 6" function called "CoordExtractor_TestBuild01()")
Link:
https://drive.google.com/open?id=1zOhwnFWZZfy9bTAxKiQFSl7qiQLlYIJV
Code snippet of the text extraction process below to reproduce the problem (given an applicable pdf is used):
Sub CoordExtractor_TestBuild01()
'Opening the PDF and getting the coordinates
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
'File Path of Text File
FilePath = "C:\Users\KAllan\Documents\WorkingInformation\sTreamTrain\Document16 - Original.pdf"
'Determine the next file number available for use by the FileOpen function
TextFile = FreeFile
'Open the text file in a Read State
Open FilePath For Input As TextFile
'Store file content inside a variable
Dim Temp As Long
Temp = LOF(TextFile)
FileContent = Input(LOF(TextFile), TextFile)
'Clost Text File
Close TextFile
End Sub
I would like someone to let me know what runtime error 62 is in this context and propose any workflows to get around it in future. Also, I would like to know whether there certain characters you cannot store as strings? - Perhaps these are included when I increase the number of vertices past a certain number.
Also I would prefer to keep the scrips quite simple and not use external libraries because I want to share the script when it is done so others can use it thus its simpler if it works without extra dependencies etc, however, any and all advice welcome since this is only the first half of this project.
Thank you very much.
According to the MSDN documentation, this error is caused by the file containing
...blank spaces or extra returns at the end of the file or the syntax
is not correct.
Since your code works sometimes on documents with very similar names and content to documents where it doesn't work, we can rule out syntax errors in this case.
You can clean up the file contents before processing it any further by replacing the code at the top of your macro with the one below. With this I can read and extract information from your Document16.pdf:
Sub CoordExtractor_TestBuild01()
'Purpose to link together the extracting real PDF information and outputting the results onto a spreadsheet
'########################################################################################
'Opening the PDF and getting the coordinates
Dim n As Long
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
'File Path of Text File
FilePath = "C:\TEST\Document16.pdf" ' change path
'Determine the next file number available for use by the FileOpen function
TextFile = FreeFile
'Open the text file in a Read State
Open FilePath For Input As TextFile
Dim strTextLine As String
Dim vItem As Variant
Line Input #1, strTextLine
vItem = Split(strTextLine, Chr(10))
' clean file of garbage information line by line
For n = LBound(vItem) To UBound(vItem)
' insert appropriate conditions here - in this case if the string "<<" is present
If InStr(1, vItem(n), "<<") > 0 Then
If FileContent = vbNullString Then
FileContent = vItem(n)
Else
FileContent = FileContent & Chr(10) & vItem(n)
End If
End If
Next n
'Clost Text File
Close TextFile
' insert the rest of the code here
I want to create a program that auto copy text file from one folder to another folder . is it possible to make in windows form in vb.net ? if not what about in console apps ? i tried to search but i didn't find an answer for both. please help me i'm new to to this. I want to copy all the text file that is being save to c:folder1\test1.text copy to c:folder2\test1.text then test2.text,test3.text all the text file that are being put in folder1. i want to copy in folder2.
now i only have this code:
it will only copy 1 specific textfile with file name test.txt.
enter code here
My.Computer.FileSystem.CopyFile("C:\CopyTo\test.txt",
"C:\CopyHere\test.txt")
Of course! First of all we need a function that search for files.
Public Sub SearchFiles(ByVal Pattern As String, ByVal Path As String, ByVal FilesFound As ArrayList)
FilesFound.AddRange(Directory.GetFiles(Path, Pattern))
End Sub
But where we should save the list of files? We can use a Array for it. Also we should define our output and input folder
Dim files As New ArrayList
Dim inDir As String = "input path"
Dim outDir As String = "output path"
We can now call this function like this:
SearchFiles("*.txt", inDir, files)
All .txt files in the folder are now saved in our Array List. But how we can work with it? We can now work with it like this:
Try
For Each file As String In files
Dim fName As String = Path.GetFileName(file)
My.Computer.FileSystem.CopyFile(file , outDir & "\" & fName, overwrite:=False)
Next
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
This will copy every .txt file that where found in our inDir to our outDir. If something goes wrong then you will see this in the console. Try it out and understand how it works :)
I got this problem at work that I have to do a lot with iManage (aka FileSite, DeskSite, WorkSite etc.) and maybe you've heard of it.
Anyways, what I'm trying to do is to write a VBA code which will be able to download a particular file based on its InFin number (7-digit number that is assigned to every file when being uploaded to iManage) and then place the file somewhere; For example, on the Desktop.
I know that iManage does expose an object model and I've already set the reference to IManExtLib.dll
I believe that the command I need is the Copy.Cmd (I don't want to cut sth from WorkSite but only download a copy of the file for the performed task).
Any help would be appreciated.
Assuming you already have a DMS session, you need to get an IManDocument object for your document you're trying to get and then call the GetCopy method. As an example, the following retrieves a physical copy of document number 123456 to a temp folder. Note you'll need to add a reference to IManage.dll as opposed to IManExtLib.dll.
Dim dmsRoot As IManDMS
Dim dmsSession As IManSession
Dim dmsDatabase As IManDatabase
Dim doc As IManDocument
Dim tempDocName As String
Const ServerName As String = "YourDMS"
Const DatabaseName As String = "YourDatabaseName"
Const DocNumToFind = 123456
Const DocVerToFind = 1
tempDocName = "C:\temp\mydoc.doc"
Set dmsRoot = New ManDMS
Set dmsSession = dmsRoot.Sessions.Add(ServerName)
dmsSession.TrustedLogin
Set dmsDatabase = dmsSession.Databases.ItemByName(DatabaseName)
Set doc = dmsDatabase.GetDocument(DocNumToFind, DocVerToFind)
doc.GetCopy tempDocName, imGetCopyOptions.imNativeFormat
I have a few files that pending on factors may require an alternate-variation to be used. The selection of the right file starts at standard windows directory C:\Drawings in my case, So I know that we can add items to the windows backbround context menu as follows:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\txtfile\shell\mymenu]
#="test123"
[HKEY_CLASSES_ROOT\txtfile\shell\mymenu\command]
#="%SystemRoot%\\system32\\NOTEPAD.EXE %1"
However (and im not sure even if this is possible) i would like to get the name of the file that was cliked and use it in my vb.net application for example a textbox wich displays that files name.
dose anybody know if i can do this? and how?
First you'll have to get the command line arguments, which can be done in a few different ways but I prefer to use Environment.GetCommandLineArgs():
Dim Arguments() As String = Environment.GetCommandLineArgs()
Then you must check that there's actually an argument to read. The very first argument (index 0) is always the path to your application, therefore we must check that it contains at least two arguments to be sure that there is also one passed to your app.
If Arguments.Length >= 2 Then
Finally you just get the path to the file from the second argument, and call IO.Path.GetFileName() on that:
Dim FilePath As String = Arguments(1) 'Second argument has index 1.
Dim FileName As String = IO.Path.GetFileName(FilePath)
If you don't want the file's path at all you can just go ahead and do:
Dim FileName As String = IO.Path.GetFileName(Arguments(1))
Full code:
Dim Arguments() As String = Environment.GetCommandLineArgs()
If Arguments.Length >= 2 Then
Dim FilePath As String = Arguments(1) 'Second argument has index 1.
Dim FileName As String = IO.Path.GetFileName(FilePath)
'Do your stuff here.
End If
Ok, here is my story:
I am building a fileviewer, and i am trying to delete the selected file in the listview.
when i try to delete it, it gave me an error saying the file wasnt found. I looked at my desktop and the file was there. here is the original code:
dim f as string = lv1.focuseditem.text
my.computer.filesystem.deletfile(f)
lv1.update()
this gave me that error. My updated code is supposed to show me where the computer thinks my file is:
Dim file As String = lv1.FocusedItem.Text
Dim testFile As System.IO.FileInfo
testFile = My.Computer.FileSystem.GetFileInfo(file)
Dim folderPath As String = testFile.DirectoryName
MsgBox(folderPath)
this shows a messagebox that shows the path of:
C:\Users\tgs266\Desktop\SIOS\SIOS\SIOS\obj\Debug\test.txt
but the real file location is:
C:\Users\tgs266\Desktop\test.txt
please help
How are you getting the filenames for the ListView? Is it just the filename and no path?
If, for example, lv1.FocusedItem.Text is "test.txt", and that is the value you use (without the path), by default the program will look in the directory it's executing in. This is most likely why you're seeing C:\Users\tgs266\Desktop\SIOS\SIOS\SIOS\obj\Debug\test.txt as the location, instead of what you expected.
If all the files are on your desktop, you can use Environment.GetFolderPath in conjunction with the Environment.SpecialFolder Enumeration to get the file, like this:
Dim file As String = lv1.FocusedItem.Text
Dim testFile As System.IO.FileInfo
testFile = My.Computer.FileSystem.GetFileInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\" + file)
Dim folderPath As String = testFile.DirectoryName
MsgBox(folderPath)
However, if you're going to have files scattered throughout your system, you'd be better off storing the full path as #Plutonix indicates in his comment.
It looks like your code is looking in your applications path on the server while you want to look at the users desktop location.