Uploading xml to windows phone 8 VB - vba

`Dim medium As String = TextBox1.Text
Dim data_xml = XElement.Load("Assets\Manager.xml")
'next quaries the xml for desired attributes
Dim query = From DataTable1 In data_xml.Descendants("DataTable1")
Where (DataTable1.Attribute("Medium").Value = medium)
Select Uname = DataTable1.Attribute("Username").Value
For Each result In query
'displays results to textbox
TextBox2.Text = result
Next
I try to use this code to read from an xml file in the assets but the file does not seem to exist
At the declaration of the xelement.load("Assets\Manager.xml") I get this error
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: Could not find file 'C:\Data\SharedData\PhoneTools\AppxLayouts\d5d3a1e7-56d7-477c-bcd2-f949f3374de1VS.Debug_AnyCPU.NAME\Assets\Manager.xml'.
If there is a handler for this exception, the program may be safely continued.
Any ideas?

Steps to make it work:
Change Manager.xml Build action to Content
Change Copy to output directory to Copy if newer
Load file using XElement.Load("Assets/Manager.xml");
Edit:
Ok, since you are not willing to share more of the code even though you ask for help, there's nothing else I can do but put up an example :)
"Software" below, implemented in Visual Basic, reads and displays XML file named Manager.xml, that is set as Content in WP8 project. Working example can be found at https://github.com/mikkoviitala/read-content-xml

Related

VB.NET open a Text File within the same folder as my Forms without writing Full Path

I found a similar question but it was 5 years 8 months old, had 2 replies and neither worked for me (VB.Net Read txt file from current directory)
My issue is that when I use the following code:
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Username_And_Password_Raw.txt")
Dim usernameAndPassword = Split(fileReader, ",")
I get an error saying:
System.IO.FileNotFoundException: 'Could not find file 'C:\Users\wubsy\source\repos\NEA Stock Page System\NEA Stock Page System\bin\Debug\net6.0-windows\Username_And_Password_Raw.txt'.'
I have tried using all the different Applications.BLANKPath options I can find (ie; StartupPath, CommonAppDataPath, etc.) and they all return essentially the same error only with a different location.
This is the folder layout of my TXT File - I know it's a terrible, incredibly insecure and generally awful way of storing login information but this is just for a NEA so will never ever actually be used
This is the actual path of the TXT File if it helps
C:\Users\wubsy\source\repos\NEA Stock Page System\NEA Stock Page System\Username_And_Password_Raw.txt
The startup path is where your exe is located. That and all supporting files get copied to a binary directory when you compile in visual studio, in your case
C:\Users\wubsy\source\repos\NEA Stock Page System\NEA Stock Page System\bin\Debug\net6.0-windows
But what you're trying to do, reference the file where it sits in your solution, is probably not the best way to do it, and your code above will work (with a change, will mention later) if you change the properties of the file in the solution.
Right click on the file in the Solution Explorer Username_And_Password_Raw.txt, select Properties. Modify Copy to Output Directory to either Copy always / Copy if newer, depending on your requirement. Now that file will copy to the same directory your exe is in, and the code above should work.
Note, when creating a path, don't use string concatenation because you may have too many or too few \; use Path.Combine:
Dim filePath = Path.Combine(Application.StartupPath, "Username_And_Password_Raw.txt"
Dim fileContents = My.Computer.FileSystem.ReadAllText(filePath)

VB.NET A generic error occurred in GDI+ when Bitmap.Save()

I'm now created an application that encode value into QR code, and turn into image. Then, I want to store the image to my local. But, I tried many solutions that I found on Google and here. The issue still prompt out unexpectedly everytime. My code and a sample error picture is shown below. Please help me!
A generic error occured in GDI+
Dim qrCodeObject As QRCodeEncoder = New QRCodeEncoder()
Dim image As Image
Dim bitmap As Bitmap
qrCodeObject.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE
qrCodeObject.QRCodeScale = 6
qrCodeObject.QRCodeVersion = 5
qrCodeObject.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H
image = qrCodeObject.Encode(value)
bitmap = New Bitmap(image)
bitmap.Save(value + ".jpg")
ANSWER: Always save file with different name and doesn't include any illegal characters
Path concatenation with simple strings is crap.
Use Path.Combine to build a path, because this ensures your path does
contain needed slashes if it would otherwise not be valid.
Dim Pat As String = Path.Combine(String.Concat(value, ".jpg"))
bitmap.save(Pat)
If this does not help, we need to know what "value" contains in your case.

Access to path is denied when trying to import from the client's desktop with SSIS

I'm creating a html page that will import an excel file in to a tracking system. On a button click event excel file is located / ssis package is fired / data imported then closed out. Thats the idea work flow. Problem is the excel file access is being denied before the package even executes
Here is the exact error :
I've tried :
excel file properties have been shared to everyone
identity impersonate set to true
hard coding the path
here is the VB code
Protected Sub bntExecute_Click(sender As Object, e As EventArgs) Handles btnExecute.Click
Dim app As Application = New Application()
Dim package As Package = Nothing
'Dim fileName As String = "C:\Users\Desktop\T. Bryant III\PTSID_Update_Template"'
Try
Dim fileName As String = Server.MapPath(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName.ToString()))
FileUpload1.PostedFile.SaveAs(fileName)
package = app.LoadPackage("#C:\Users\Desktop\T.Bryant III\KitImport", Nothing)
'excel connection from package'
package.Connections("SourceConnectionExcel").ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0data source =" + fileName + "Extended Properties = Excel 8.0"
'Execute the pakage'
Dim results As Microsoft.SqlServer.Dts.Runtime.DTSExecResult = package.Execute()
Catch ex As Exception
Throw ex
Finally
package.Dispose()
package = Nothing
End Try
End Sub
Thanks in advance or if there is an easier way to do this please let me know. The package when executing it in ssis works fine with its own connection manager etc.
A few things to try. If they don't work for you as permanent solutions, they should at least confirm that your code is working and you are dealing with a persmissions issue (which appears to be the case).
Move your file to the public folder (C:\Users\Public).
Run your application (or web browser) as an administrator (if applicable to your version of Windows).
If you are using a web browser, try using a different one.
If nothing else works, try pasting your code into a Windows Form Application.
If you still get the same error after trying all of this, it's time to take another look at your code. Remove the Try/Catch block to determine precisely which line is throwing the error. If you've tried hard coding, I'm guessing it's the SaveAs method. I'm not sure what class FileUpload1 is, but some SaveAs methods won't overwrite existing files unless you explicitly tell them to. Check the appropriate documentation and see if you don't need to pass a True value somewhere along with filename.
Update us with the results. At the very least, this should narrow down your problem and allow for a better diagnosis of it.

Can't save to embedded xml document

In a VB.NET project I have an xml document as an embedded resource. I am accessing it with
Private xmlFile as New XmlDocument()
in the General Declaration area. And then I am loading it in the form load method:
xmlFile.LoadXml(My.Resources.Settings)
In a method I'm finding specific nodes and updating them from user input:
'Dim xmlDoc as XmlDocument
'xmlDoc = xmlFile
Dim settingNodes As XmlNodeList = xmlFile.SelectNodes("//Program/ProgramTitle")
For Each setting As XmlNode In settingNodes
If setting.InnerText = title Then
setting.ParentNode.Item("ProgramSaveFolder").InnerText = programFolder
setting.ParentNode.Item("PrimaryBackupFolder").InnerText = primBackup
setting.ParentNode.Item("SecondaryBackupFolder").InnerText = secBackup
End If
Next
' Neither of these work
xmlFile.Save("Settings.txt")
'xmlDoc.Save("GameSettings.txt")
The xmlDoc code is from when I was led to believe at one point that it's not saving because xmlFile was in use (I've been trying a lot different things!).
But, as noted in the code, neither of those work. This is very similar to what I see all over for examples of how to do this, but when I run the program it doesn't change the file at all.
You cannot modify an embedded resource. You can include the XML file as content and it will appear in your build folder as a normal file that can be loaded and updated using the File.IO namespace or XMLDocument.Load().
One catch to look out for is that a file in the Program Files folder being modified will require administrator rights which a user may not have. If this is the case, it's best to copy the file to the AppData folder.

Program freezes when saving images in vb.net

I have created a winform program in visual studio 2012 that saves a image loaded into a picture box when another button is clicked. I first get the file path from the user with:
PrePath = {FileSave.Text,"RawData",Welcome.File(nextimagecounter)}
Path = IO.**Path**.Combine(PrePath)
Imagea.BackgroundImage.Save(Path)
Where PrePath is a String Array, Path is a string, FileSave.Text is user input in a txt box, Welcome.File(nextimagecounter) is a string that was stored in array File (found using .GetFiles) Path = IO.Path.combine(PrePath), Imagea.Backgroundimage is the background image I want to save.
When I do this my program will freeze and I need to go to the task manager to end it. It also throw this error
An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
System.Drawing.dll
Additional information: A generic error occurred in GDI+.
Please note I also tried doing the call by:
Imagea.Background.Save(FileSave.Text+"\RawData\"+Welcome.File(nextimagecounter)+".jpg")
This did not work either, another post lead me to Path.Combine. Any help would be greatly appreciated!