Illegal character in path (of Resources file) - vb.net

I have a Windows Control Library project (visual studio 2010). I put in the compile tab for it to be a com element (I use it as an addin for another program).
My question is the following:
I have a .cvs file in my resources that I use to parse some main settings.
The line of code that reads this file gives an error when I run the addin.
code line:
dim reader as new streamReader(My.Resources.standards)
(the file is called standards)
error I get when running the com element:
Illegal character in path.
The program runs nicely when I test it as a normal windows form project.
Anyone know how to fix this? Or how to do decent debugging when testing com elements.
Thanks.

This does not have anything to do with COM, scratch that as a cause of your problem. Clearly your My.Resources.standards property returns a string, not a stream. Which is pretty normal when you add a text file as a resource. It makes StreamReader try to open a file on disk using the content of the .cvs resource as the path of the file. That will of course not work well.
You could use a StringReader instead. Or just use the returned string as-is.

Change it to following
dim reader = new string(My.Resources.standards)
you have a string now that can be used in regex
Cobus

Related

How do I embed an exe file in an MS Access Form and Run it at run time?

I'm using MS Access 2003 for Special and old problems with the .mdb project
I want to embed my files like .txt or .exe or .pdf and run them at runtime or write that on disk.
What have I tried :
enter image description here
I don't know what's the code to do what I need I couldn't find my solution on internet.
Private Sub Form_Load()
'Me.OLEUnbound2.Application.Run
Dim obj As Object
Set obj = Me.OLEBound1.Object
'obj.DoVerb (acPrimaryVerb)
End Sub
Update:
I wrote a C# program called BMH.exe, which I open and run through Access, but I want this file to be in my source in any way possible so that the user does not have to place this file next to the program or somewhere It has Windows,
I also don't want to do things like downloading from the site, creating an installation file, I just want to access this program in any possible way through the embedded file itself, which is in the form of OLE Object and from the Packager Shell class. Write the object to a specific address or run it directly from Access itself
You can save the file as attachment in attachement field. If it will not accept an .exe file switch the extension and switch it back when exporting, you can do all this with code. Alternatively you can store the file as binary in an Ole field.

Create Document in the Folder the EXE is in (VB)

I'm starting to play around with FileStream to make a text document. When you do this, you have to clarify a path. Is there a way to create the text document in the folder the EXE file is in?
(I'm asking this because this program is meant to be downloaded, so I think I can't clarify a path specific to my computer)
Thank you!
You're right, you can't bake a path into your program that is specific to your computer because then it won't work on the user's computer
Jimi makes the wise point that often programs are installed to C:\Program Files or similar and it's not automatically possible to write to subfolders in there - you'll have to get into asking the user for permission (Elevation) .. headache
Better to decide what you want the path for:
If you need a temporary path to e.g. download something to then throw it away you can call Path.GetTempFilename() or Path.GetTempPath() - the former creates a 0 byte file with a random name in the user's temp folder, and returns the path. The latter gives you the path to the temp folder so you can create your own file
If the file is to have some permanence, such as the user saving his work, you should ask the user for it. SaveFileDialog and FolderBrowserDialog are two things you can drop on your windows form and then call ShowDialog() on to show the uer a UI where they pick a path. After they OK or Cancel, you check if they OK'd or Cancel and proceed using the dialog's Filename or SelectedPath respectively (if they OK'd)
When you're writing your files it's easier not to use FileStream unless you really need to seek in the file etc. Easier to just:
System.IO.File.WriteAllText(path here, contents here)
If you have to write the contents of a string variable to a file
The best way to create a text file, would be to use CreateText method. It will create a file besides the executable program file. You can go the following way.
Dim sw as StreamWriter = File.CreateText("myfile.txt")
Dim str as String = "Your text"
sw.Write(str)
sw.Flush()
sw.Close()

Trouble specifying path to open Excel woorbook in vb.net app

I have a WFP app that works well. I open an Access DB and want to do the same with an Excel workbook. Opening the DB is not an issue as I am able to remove the drive letter from the path. I am having a bit of an issue with the search path for the workbook. My path operates as expected when the drive letter is specified [here is the line of code that works properly -- xlWorkBook_AR = xlApp_AR.Workbooks.Open("S:\11_2017_Spring\MPRecords-2\Accounting\FinancialSystem.xlsm")]). When I remove the drive specification from the path it does not operate as expected. I receive an error stating the file is not found. What do I need to do to make this dynamic?
Thanks in advance.
Ed
Try this (if it works for your scenario):
Place the excel file in the same folder as your app (.exe) (I assume this works for your needs).
Use this code to dynamically get the path of your app, and then add on the name of the file, something like the below:
Application.StartupPath & "\FinancialSystem.xlsm"
Supply this to excel's .Open method and I believe it will work.
You will need to import System.Windows.Forms. Read about Application.StartupPath property here: https://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath.aspx

Opening PDF from a DataGrid

I have a DataGrid that reads from a table in a DB the name and file name (full address) of certain files. What I want is when the user double clicks the file it opens the PDF reader and loads the file. How would I go about doing this?
EDIT: This is my current code:
Dim row2 As String = DataGridView1.Rows(e.RowIndex).Cells(3).Value
Process.Start("Acrobat.exe", row2)
VS throws the exception that file cannot be found. I checked the variable and its giving me the correct data. I also tried putting row2 between the quotation marks and no go either. It just doesn't find the file.
WORKING UPDATE: Alright it was a very simple mistake
Process.Start("AcroRd32.exe", row2)
Row2 grabs the data from a cell I have in the datagrid that has the file location.
Process.Start("filename") will open a file using the default application on that machine.
In most cases, the above approach is correct. It is not dependent on a particular application or particular version of the application being pre-installed on the target machine. The advantage is loose coupling between your application and the PDF viewer.
If you really need to, you can use Process.Start() to launch a particular program, many of which will accept a filename as a command line parameter, like so:
Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
(This example taken from the linked MSDN documentation)
You can find a list of Adobe Reader's command line arguments here:
Adobe Reader Command Line Reference
Update: The above link is old (focuses on version 7). You can find version 8 documentation here:
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
I cannot find a reference for version 9.

Opening a file in my application from File Explorer

I've created my own application in VB.NET that saves its documents into a file with it's own custom extension (.eds).
Assuming that I've properly associated the file extension with my application, how do I actually handle the processing of the selected file within my application when I double click on the file in File Explorer?
Do I grab an argsc/argsv variable in my Application.Load() method or is it something else?
Try this article but short answer is My.Application.CommandLineArgs