Hi, if someone on here could help me, I'd really appreciate it.
I am currently building a program that will be able to open excel and word documents in their appropriate programs. Heres my code:
Dim
Job As String = txtJob.Text Dim str2File As Stringstr2File =
""str2File = Application.ExecutablePath
str2File = str2File.Substring(0, str2File.LastIndexOf(
"GaugeHelper.EXE")) Dim wordstart As New Processwordstart.StartInfo.FileName =
"winword.exe"wordstart.StartInfo.Arguments = str2File &
"\Reports\" & Job & "\" & Job & ".doc"w.Start()
I can get it to work, except for one thing, When you use the common folder name \Documents and Settings\
Word will try to open Documents.doc, and then it will try to open settings\(rest of the pathname)
Is there a hidden character that can take the place of a space that you are able to insert into quotes that will prevent this from happening because i can do this manually, but the folder with the documents and spreadsheets in them has to be on the desktop.
Please Help
-Thankyou
Anthony

C:\Documents and Settings\...\My Documents\Visual 2005\...\bin\debug\Reports *Spaces will not let me open .doc file in word*
Udo Kroon
MLatchmansingh
oo, thats awesome. Thankyou so much. It works when i test it within VisualStudio, but im still encountering a similar error. When i take the application out of bin/release and try to use it how it should be used, it comes at me with this error.
Because the way this program is supposed to be designed for is to open files for people whom don't want to go fishing around for purchase orders at my work. All of the purchase orders are in one place, therefor the program needs to look in /Reports/ in the program's main directory. Thats why i used the approach of Substringing the filename's exe out of the application.path, so no matter where the program was, it would look for /Reports/
But when i try to put it into effect...it doesnt work unfortunately.
Btw, i really appreciate the help, its my first time posting on MSDN.
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at Gauge_Helper.Form1.Button2_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Austin Milbardge
str2File = str2File.Substring(0, str2File.LastIndexOf("GaugeHelper.EXE"))
The above code statement was trying to findout GaugeHelper.EXE in the AppPath and it was searching that with case sensivity. When you were trying to run it from VS there might be possibility that the AppPath was .....\GaugeHelper.EXE but when you were trying to execute the application from outside VS the apppath might changed to ....\GaugeHelper.exe which made str2File.LastIndexOf("GaugeHelper.EXE") return -1 and the whole statement turns to
str2File = str2File.Substring(0, -1) which is not a valid statement
with my code what i did was just replaced str2File.LastIndexOf("GaugeHelper.EXE") with str2File.LastIndexOf("\") as there is 100% possibility that the AppPath has "\" and thats too just before the EXE name then we finally add "\" to the string before appending anything else to that path.
Please do let me know if you need any further clarifications.
bkohler
WooT!! Thanks so much!! It works great now! =)
ty again
Could you maybe tell me why changing it to that makes it work
Leo Kent
Ah! dont worry about it, sorry for the post above, i have an alternate method of retrieving the documents creation date
but thanks!
=)
djt69
Replace
str2File = str2File.Substring(0, str2File.LastIndexOf("GaugeHelper.EXE"))
with
str2File = str2File.Substring(0, str2File.LastIndexOf("\")) & "\"
Martin123
Wow, thankyou so much. It makes a lot of sense. I really appreciate you taking the time to explain it to me. I am taking computer programming in college right now, but my instructor is a dingbat and doesn't know any of the answers to any of the questions i ask. His response is always..."Go look on MSDN, im sure someone else has had the same problem in the past..."
Aaaaanyway...
Thanks again. Do you know of a way to gather a file's properties and display it in a label or something similar
=(sorry for asking so many questions... =P
Dave_L
normanbates
try this code
Dim
MyFileInfo As System.IO.FileInfo = New System.IO.FileInfo("File Path Goes Here") and then go and try the various properties available inside MyFileInfoto include few you can get
MyFileInfo.Attributes
MyFileInfo.CreationTime
MyFileInfo.CreationTimeUtc
MyFileInfo.DirectoryName (This could give you the complete path where the file exists , you can also use this directory name inplace of SubString :) )
Well MSDN is always a good resource but then he should not be called a trainer :D
Tom Sapp
Ive done some testing and ive come to the conclusion that something is wrong... =P
So, When i debug the program it works...but when i attempt to run it, i get the error described above...
Testing Process
-----------------------------
Tested program in visual studio
Result: No errors
-----------------------------
Tested program by going to Program1\Program1\bin\debug
Result: Error
-----------------------------
Tested program by going to \Program1\Program1\Bin\Release
Result: Error
-----------------------------
woodland30033
This is what ive come up with so far, the comments were just reference for myself.
But! this doesnt work...=P
unfortunately...
Private Sub btnDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDate.Click
Dim varMonth, varDay, varYear As String
varMonth = txtMonth.Text
varDay = txtDay.Text
varYear = txtYear.Text
Dim varDate As StringvarDate = varMonth &
"/" & varDay & "/" & varYear Dim varPlaceholder = "" Dim filepathdate As Stringfilepathdate = Application.ExecutablePath
filepathdate = filepathdate.Substring(0, filepathdate.LastIndexOf(
"\")) & "\" Dim filepathdate1 = filepathdate & "\Reports\" 'Dim MyFileInfo2 As System.IO.FileInfo = New System.IO.FileInfo(varPlaceholder) 'Label2.Text = MyFileInfo2.CreationTimeUtc For Each fileName As String In My.Computer.FileSystem.GetFiles _(filepathdate1, FileIO.SearchOption.SearchAllSubDirectories,
"*.doc") Dim file As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(fileName)Debug.WriteLine(file.CreationTime)
Debug.WriteLine(file.LastWriteTime)
Debug.WriteLine(file.Length)
Next 'Dim filepath4 As String 'filepath4 = "\Reports\" & filepath0 & "\" & filepath2 End SubManishMenon
lol, yeah i agree completely...He shouldnt be teaching.
Thanks again.
maqk
Im also thinking about a comparing code, and if it comes up true, then open the file...
Psuedocode
sorta like...
if Date is = fileInfo.creationTimeUtc
then
open file
bharathi_tunes
you need to wrap the path in quotes, which are represented as """" ( they need to be wrapped in quotes themselves) e.g. wordstart.StartInfo.Arguments = """" & str2File & "\Reports\" & Job & "\" & Job & ".doc" & """"