I am using the below bcp command to export the binary files from the filestream db and all other files are seems to be exported fine (i.e. txt, pdf, rtf, image files & etc) except docx, xlsx & pptx files. I am able to export these files (i.e. docx, xlsx & pptx) but I am getting a warning/error message when opening those files and then it opens the file properly.
BCP "SELECT content FROM [dbo].[Contents] WHERE ID=1" queryout "C:\Temp\" -T -S (local) -f C:\Temp\files.fmt
I am getting the below message when opening docx, xlsx & pptx files:
XLSX - Excel found unreadable content and Do you want to recover the contents of this document?
DOCX - The file test.docx cannot be opened bcos there are problems with the content and then Excel found unreadable content and Do you want to recover the contents of this document?
Also, I have this in my files.fmt file:
10.0
1
1 SQLBINARY 0 0 "\t" 1 content ""
Any help will be much appreciated.
I am not 100% sure if your problem was the same as what I have had but in my case, I found that the problem was actually in the writing part, not in the reading part. For example, my original writing code was like this:
Dim FILE_CONTENT(len) As Byte
File.InputStream.Read(FILE_CONTENT, 0, len)
SaveFileToDatabase(FILE_NAME, CONTENT_TYPE, FILE_CONTENT)
When I changed the first line as the following :
Dim FILE_CONTENT(0 To len - 1) As Byte
the reading error disappeared. I just forgot that VB actually allocates N+1 bytes (O to N) by default when you dimension it without specifying the lower bound. See similar situation described here: Uploaded Docx Files are getting corrupted . hope that helps.
Related
I am trying to read and edit a file within a gzip file. I can do this with .zip files, but I get an error when trying to read the .gzip file.
Search results so far only talk about compressing or decompressing .gzip files.
If relative, the .gzip file (as per file properties) actually has a ".dat" extension. The file I need to edit within it doesn't have any extension.
Using archive As ZipArchive = Compression.ZipFile.Open(Path.Combine(SelectedWorld, "level.dat"), ZipArchiveMode.Update)
Dim entry As ZipArchiveEntry = archive.GetEntry("level")
Dim s As String = ""
Using sr As New StreamReader(entry.Open())
s = sr.ReadToEnd()
End Using
Dim M As Match = Regex.Match(s, "LevelName")
If M.Success Then
MsgBox(M.Value)
'edit word after "LevelName" <<I'm going to need help with this too.
End If
End Using
The above code throws the following error:
System.IO.InvalidDataException: 'End of Central Directory record could not be found.'
Trying the following doesn't seem to have the right stuff to read/modify a file.
Using archive As IO.Compression.GZipStream = IO.Compression.GZipStream
I have found little else for dealing with these types of files. Any help would be greatly appreciated.
A gzip file is not a zip file. Two entirely different things. The error about not finding an end-of-central-directory record is something only found in a zip file.
A zip file is an archive, with files stored within that are independently compressed. That permits removing and adding some files without having to recompress the other files. Though the whole thing will need to be copied to move things around.
A gzip file stores only one compressed file. If you want to edit that one file, then simply gunzip it, edit it, and then re-gzip it.
Often the one compressed file in a gzip file is itself an uncompressed tar archive of many files. The extension of the file will be .tar.gz. If you want to edit the tar archive, again you would gunzip it to get a .tar file, edit it with the tar command, which can delete and append files, and then re-gzip it.
I got it working using:
Imports Cyotek.Data.Nbt
NewName = InputBox("Enter New Name")
Dim MyFile As String = Path.Combine(SelectedWorld, "level.dat")
Dim document As NbtDocument = NbtDocument.LoadDocument(MyFile)
Dim root As TagCompound = document.DocumentRoot
root.Name = "Data"
Dim TC As TagCompound = root.GetCompound("Data")
Dim MyTag As Tag = TC.GetTag("LevelName")
MyTag.SetValue(NewName)
document.Save(MyFile)
Ive tried using several methods to save images, one was using binary code. the issue with that is that it saves a few hidden characters in the file name, and then the file becomes funky, where the only program that can open it is mspaint, and when i try to resave the file, it defaults to wanting to save the image as *heic format.
anyone have any ideas on how to save an inlineshape in Word to your desktop.
```
Open strOutFileName For Binary Access Write As #1
i = i + 1
vData = shapeCurrent.Range.EnhMetaFileBits
lWritePos = 1
'put writes to the file that has been created
Put #1, lWritePos, vData
Close #1
```
I am using openpyxl (2.3.2) to write out an xlsm file. I can write the numeric values correctly but the string values are corrupting the xlsm file. In the code example below, the xlsm file is corrupted but the xlsx file works well
When I open the xlsm file , I get a error
we found a problem with some content in samp2.xlsm
On continuing, I see only the numeric values are written and not the string values. This does not happen with the xlsx file.
This is a strange problem
PS The "Samp.xlsm" and "Sample.xlsx" Files are new files saved with these names. They do not have any content.
Appreciate any suggestions/feedback
So, basically, without having any Visual Studio experience, I wanted to improve my animation workflow. So, I wanted to use stuff found in http://www.aseprite.org/cli/ to do that.
So, I made a little program to get all .ase files in a folder and make a text file containing the lines needed for the batch file to convert the said .ase files to either .gif or png files. I'm stupid, so I manually convert the text file to a .bat file.
But the .txt files generated from the program do not work when converted to .bat, but if I copy the lines to another .txt file I create in windows, and convert it to .bat, it works.
So the question is - do I corrupt the .txt file in Visual Studio or something?
If there's a problem with the code, I'll share it, but I'm reluctant, cause I don't want to have a formatting mistake nightmare.
Oh, and yeah, I know this isn't a smart way to go about.
EDIT: Ah, right, the error of the batch file, which, by the way, flashed by extremely quickly and closes the command line prompt: '--batch' is not recognized as an internal or external command, operable program or batch file.
The code in .bat is like:
#set ASEPRITE="C:\Program Files\Aseprite\aseprite.exe"
%ASEPRITE% --batch animation.ase --scale 2 --save-as animation-x2.gif
%ASEPRITE% --batch animation.ase --scale 4 --save-as animation-x4.gif
And basically in VB I create the txt file and text like this:
' Dim fs As FileStream = File.Create(Label1.Text + "\Text.txt")
fs.Close()
For Each foundFile As String In My.Computer.FileSystem.GetFiles(Label1.Text)
Dim check As String = System.IO.Path.GetExtension(foundFile)
If check = ".ase" Then
ListBox1.Items.Add(Dir(foundFile))
str = Dir(foundFile)
str = str.Replace(".ase", fType)
My.Computer.FileSystem.WriteAllText(Label1.Text + "\Text.txt",
"%ASEPRITE% --batch " + Dir(foundFile) + " --scale " + fSize + " --save-as " + str + vbCrLf,
True)
End If
Next
'
You can try to write the file with a specific encoding:
File.WriteAllText(path, text, Encoding.UTF8) ' or UTF or ASCII
It could also be that the UTF8 encoder uses a Byte Order Mark which can't be read:
File.WriteAllText(path, text, new UTF8Encoding(false))
The other thing to look for is end of line characters. Is it \r\n or just \n?
You can use a file comparer to check the difference between the files, and it should become clear what the difference is.
I'm trying to pull some data from a large PDF file in VB.Net I found the following code online, but it's not helping:
Sub PrintPDF (strPDFFileName as string)
Dim sAdobeReader as String
'This is the full path to the Adobe Reader or Acrobat application on your computer
sAdobeReader = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"
RetVal = Shell(sAdobeReader & "/P" & Chr(34) & sStrPDFFileName & Chr(34), 0)
End Sub
I'm really lost. Any ideas?
/P will just display load the file and display the Print dialog - dead end.
You will probably need a library of some sort to get to the contents of the PDF.
If the file has a very simple structure you maybe able to extract the data just by reading the bytes. See if you can open it with a file like Notepad++ and see the contents.
BTW VS2010 has several editors for looking at/editing files:
File, Open File... pick the file then use the dropdown on the Open button.