Sharpcompress write in Program Files folder - vb.net

I'm trying to write some files in my folder which's inside Program Files folder... I'm getting error "Access denied" every time I try to write them... I tried to open the .exe (which makes the extraction) in Administrator mode and change folder rights to "Everyone"/"All Rights" and I still got problem with permissions.
Code:
Using archive As IArchive = ArchiveFactory.Open(PastaDownload & "\" & NomeRAR)
For Each entry In archive.Entries
If Not entry.IsDirectory Then
entry.WriteToFile(PastaSistema, New ExtractionOptions With {.ExtractFullPath = True, .Overwrite = True})
End If
Next
End Using

Related

During design/debug process, where do files created in LocalAppData directory go?

I feel really stupid for having to ask this (I'm not a professional): during the development/design/debugging process, where do files created in the LocalAppData go? I haven't yet finished my project, so it hasn't yet been installed on any machines. Parts of my code are supposed to write information to a text file in the LocalAppData directory. However, when I run my program for testing/debugging, the text files are nowhere to be found.
Dim dir As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData) & "\MyFolder\"
Dim path As String = dir & DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") & ".txt"
If Not Directory.Exists(dir) Then
Directory.CreateDirectory(dir)
End If
Using writer As New StreamWriter(path, True)
writer.WriteLine(message)
writer.Close()
End Using
Are these files being created somewhere else? Are there special dummy folders hidden somewhere for development purposes? I tried changing the directory to Desktop and it worked. What gives?

How to access disk in network

i have routine for store somes documents into one directory wich run on local drive but get error with network drive if i use path as this "\\172.16.3.145\Directory".
i use this code for create subdirectory needed:
If My.Computer.FileSystem.DirectoryExists(PercorsoDocumenti) = False Then
My.Computer.FileSystem.CreateDirectory(PercorsoDocumenti)
End If
If My.Computer.FileSystem.DirectoryExists(PercorsoOrdini) = False Then
My.Computer.FileSystem.CreateDirectory(PercorsoOrdini)
End If
'+++ creazione della sottodirectory per l'ordine che deve sempre esistere per poter consultare i files presenti +++
If My.Computer.FileSystem.DirectoryExists(PercorsoOrdini & lblIdOrdinePassato.Text) = False Then
My.Computer.FileSystem.CreateDirectory(PercorsoOrdini & lblIdOrdinePassato.Text)
End If
LstViewDocumentiCaricati.Clear()
For Each fileName As String In IO.Directory.GetFiles(PercorsoOrdini & lblIdOrdinePassato.Text)
ImgLstFiles.Images.Add(Icon.ExtractAssociatedIcon(fileName))
LstViewDocumentiCaricati.Items.Add(IO.Path.GetFileName(fileName), ImgLstFiles.Images.Count - 1)
Next
This code work and create directory also in path as "\\server\directory" but get error when i try to list all files in a listview with this other code:
For Each fileName As String In IO.Directory.GetFiles(PercorsoOrdini & lblIdOrdinePassato.Text)
ImgLstFiles.Images.Add(Icon.ExtractAssociatedIcon(fileName))
LstViewDocumentiCaricati.Items.Add(IO.Path.GetFileName(fileName), ImgLstFiles.Images.Count - 1)
Next
The error happen also if i share directory with sufficient permission...it create directory on network drive but go on error when try to list files.
The error are similar to this:
Value of \172.16.3.145\Directory\Docs\document.pdf is not a valid path for filePath
I'm not able to debug in production computer, so i think the error is in listing procedure code because all code firs work (create directory on network drive).
Someone could help me to understand why ?
With code provided in the link How to get the associated icon from a network share file all works perfectly. Tested today with no error or problem. Thanks to all!

Permission denied on file deletion and previously copied in VBA

Facing one issue....
Basically, I have a bouton on Word to launch a macro treatment. This treatment saves the open file, copies the open file from C:/ to Z:/, writes an XML file in Z:/, launches another treatment that will read both files in Z:/ and then, clears the files in Z:/.
C:/ is my local computer, Z:/ is a shared drive...
I managed to copy the file from C:/ to Z:/ with :
fsoObject.CopyFile ActiveDocument.Path & "\" & ActiveDocument.name, "Z:\" & ActiveDocument.name, True
Treatment goes well, but I'm completely unable to delete the file in Z:\ with this :
fsoObject.DeleteFile "Z:\*", True
I always get "Permission Denied"... Cannot delete it manually as well, except if I close ENTIRELY Word (and not only the file that was copied)...
Is there a way to avoid the file locking by Word ?
Thx !
Use a vba command to close the file after you have performed your operations. Then apply the delete command.

UnauthorizedAccessException with File.AppendAllText in VB.NET

I have recently started getting System.UnauthorizedAccessException errors when using File.AppendAllText to write to a shared drive on the network. I think there were some changes to the network when this happened. The code in my application hasn't changed.
I have asked our IT dept to grant me full permission to the folder. I can see I have permissions for Modify, Read & Execute, Read, Write under my username if I navigate to the file and look at the Security tab under properties. I am also part of a group with read, write and modify permissions to the folder.
This works without error in the same folder:
File.WriteAllText(myFile, myText)
This generates a System.UnauthorizedAccessException error when it reaches the AppendallText:
If File.Exists(myFile) = False Then
' Create a file to write to.
Dim createText As String = logTime & " " & report_data
File.WriteAllText(myFile, createText)
Else
Dim appendText As String = logTime & " " & report_data
File.AppendAllText(myFile, appendText)
End If
I have tried deleting the file and creating it again, that made no difference.
I tried File.SetAttributes(myFile, FileAttributes.Normal)
The IT dept can't see what the problem is.
I can manually open, change and modify the file. The problem only arises if I am trying to do this programmatically.
Is there a different 'user' which tries to modify files? Could the file be open somehow, or would that generate a different error?
I'm using VB.NET 2012, .net framework 4.5, Windows 8.1
The network changes were the problem. It doesn't seem possible to resolve this as it is. Instead I made a copy of the text data, append my new text to that, delete the file, and save the updated text to a new file.

How to use Process.Start

I'm using process.Start to run Convert.exe. This program's purpose is to convert all files which are in the exe's folder. So when I normally use it, I copy paste a file into the same folder as Convert.exe and then run Convert.exe. Convert.exe will create a new "converted" file in the same folder.
I'm trying to automate this tedious process. A User selects a file which needs to be converted from FolderA, I copy it to the same folder where Convert.exe is and I'm using process.start(Convert.exe) to run it.
Just to be clear, this "Convert.exe" accepts NO arguments.
The problem: "Convert.exe" is not converting the files in its folder. Instead it's converting all the files in FolderA for some weird reason. I don't know why it picked that folder, I never even try to send it as an argument or nothing.
Here's the code I have:
Dim techInfo As New System.IO.FileInfo(itm.strFilePath)
techInfo.CopyTo(ConverterPath & techInfo.Name)
Dim procInfoConvert As New ProcessStartInfo
procInfoConvert.CreateNoWindow = False
procInfoConvert.Arguments = ""
procInfoConvert.FileName = ConverterPath & "Convert.exe"
Dim procConvert As Process = Process.Start(procInfoConvert)
I did a test where I copy pasted a file into the "Convert.exe" folder and then just run this code:
process.start(ConverterPath & "Convert.exe")
The exe returns nothing, same as if there was no files in the folder.
The only thing I can think of is that when process.Start is run, it copies the file to another location and runs it from there.
Any ideas anyone?
Try this:
procInfoConvert.WorkingDirectory = ConverterPath
That'll set the process up to start in the directory it's contained in, instead of the current directory.