LINQPad script directory? - linqpad

Does anyone know how to get hold of the path to the directory where the LINQPad script file (.linq) resides?
Or to the script itself for that matter.
Note that I'm not talking about the location of the "My Queries" folder, the one shown inside LINQPad.
I can save a .linq file anywhere on disk, and open it by double-clicking on it.
For instance, if I save the file to C:\Temp\Test.linq, and execute the program, I'd like to have either C:\Temp or C:\Temp\Test.linq.
Basically I'd like something akin to Environment.CurrentDirectory or Assembly.GetEntryAssembly().Location, just for the .linq file.
Things I've tried:
Looking through environment variables
Looking through the LINQPad assembly that is given to my script
Throwing an exception and looking at the stacktrace (contains a link to a temporary copy of my script somewhere else)
Environment.CommandLine.Dump(); - gives LINQPad executable
Environment.CurrentDirectory.Dump(); - gives C:\windows\system32
Assembly.GetExecutingAssembly().Location.Dump(); - gives temp directory

I've just added a feature to address this. You can test it now by downloading the 2.27.1 or 4.27.1 beta build.
To get the current query's folder, use the following expression:
Path.GetDirectoryName (Util.CurrentQueryPath)

I presume you mean programatically and not through the UI itself.
The path to the linq file directory is held in
%APPDATA%\LINQPad\querypath.txt

The next question after "How do I get LinqPad script directory" is "How do I set it?" below is how you do it and link to where I found the answer
Directory.SetCurrentDirectory (Path.GetDirectoryName (Util.CurrentQueryPath));

Related

Finding and running FindSQLInstall.vbs script file

I have the problem and I'm trying to resolve it by following this link
https://support.microsoft.com/en-ca/kb/969052
However, when it says
"To complete the steps in this procedure, you have to copy the FindSQLInstalls.vbs script from the "More Information" section to a local folder on the computer where you are trying to update your SQL Server installation."
I'm confused on how to find this "FindSQLInstall.vbs" file and how to run it.
I'm just a beginner, so any help would be greatly appreciated.
I encountered this error while trying to put SP3 on SQL 2008 R2. Some research lead me to the same article https://support.microsoft.com/en-ca/kb/969052 and the FindSQLInstall.vbs Script.
I also do not have a lot of experience with command prompt or .vbs I do have some coworkers who have previously worked through the same issue. If you have found the Microsofts kb/969052, in theory everything you need is there. But if you are like me you need a bit more. This is what I did.
Note that I was VERY Lucky, We have a share folder where we keep copies of all of the upgrade/updates that we install. The .vbs found and copied many of my missing things (though it took me a while to figure that out)
Create folder on the server for working on issue 'C:\Repair_msi' = This puts all my housekeeping in one place
Save FindSQLInstalls.vbs script from https://support.microsoft.com/en-us/kb/969052#bookmark-script in this folder
Create text doc, paste in the script and rename as 'FindSQLInstalls.vbs' you will probably need to show hidden extensions to convert from .txt > .vbs
In command prompt type cd C:\Repair_msi = cmd working in this folder
In command prompt type Cscript FindSQLInstalls.vbs ServerName_sql_install_details.txt
Open the new document 'ServerName_sql_install_details.txt' which is now in this folder
The document says the .vbs found and copied over several missing .msi files
Missing cache file replaced by copying....
Previously missing package C:\Windows\Installer\67fe40cc.msi now exists in the Installer cache.
Validated that .msi files that were reported as missing on first error, have been identified by the .vbs and are now in C:\Windows\Installer
DOES NOT exist, directions do occur, called out with
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! C:\Windows\Installer\4541a.msi DOES NOT exist in the Installer cache. !!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The path called out in action plan is temp folder on the PC of a coworker who did a previous install, no hope of recovery from there.
No action taken
Rename 'ServerName_sql_install_details.txt' > '1-ServerName_sql_install_details.txt'
In command prompt type Cscript FindSQLInstalls.vbs ServerName_sql_install_details.txt = Run the .vbs again
Open the new document 'ServerName_sql_install_details.txt' which is now in this folder
New document is essentially the same as old, except it now says the previously missing .msi are now present and gives some direction if you still get errors on update
The 'DOES NOT exist' item still exists. I used crtl+F to search the document and this is the only required thing listed.
Copy "C:\Users\NAME\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\LWRNT0CZ\SQLServer2005_BC[1].msi" C:\Windows\Installer\4541a.msi
We have a folder with pretty much every SQL install and upgrade, on searching I find multiple SQLServer2005_BC.msi but no 4541a.msi
More reading and I learn that we need to find the correct version of SQLServer2005_BC.msi; copy and rename it to 4541a.msi
Can't find version numbers for the 30+ versions we have on the share....
Maybe we don't really need that one?
Try the SP install, It does not error out, I get to the Install now step (first attempt errored very early)
Pending off hours time slot to apply SP to this production server
In summary
It turns out I could have just run the FindSQLInstalls.vbs Script and then run the SP install again. The .vbs will return results which include the place the file was when it was last used as well as the version number. If the .vbs does not find it there, you will need to find what it wants, copy it and rename it with the correct name and put it the correct place.

Can't copy to network path using Filesystem.filecopy or FileSystem.CopyFile

I'm trying to copy a file from a local computer to a remote share but I get an exception saying "Can't find the specified file".
My.Computer.FileSystem.CopyFile("C:\filename.jpg", "\\focserver2\consultoria\teste\filename.jpg")
The remote shared folder has full control permissions on "Everyone".
What am I doing wrong? Or it's not possible to copy to network paths using FileSystem.CopyFile ?
Thanks.
João
The issue does not appear to be the destination but the source. I assume that the sample you showed above is NOT the real code and in the real code, you combine a couple values together to define the source. To help prevent issues, get in the habit of using the Path.Combine() method when concatenating strings for a file path. It's a life-saver.
The next most important thing is to learn how to debug your code by setting break-points and seeing what the values of your combined strings are before posting to websites. This is a good one to get you started. http://weblogs.asp.net/scottgu/debugging-tips-with-visual-studio-2010
Most likely the problem is that you are trying to access the root folder of the C:\ drive. This folder is generally locked down by the operating system, and even simple file operations don't work easily there.
Try copying the file from a subfolder e.g.
My.Computer.FileSystem.CopyFile("C:\Temp\filename.jpg", "\\focserver2\consultoria\teste\filename.jpg")

Get File when given Server File Location

Is it possible to get the actual file, or the file that gets copied from version control to a location?
This sounds confusing. Basically I have the file path of the version controlled file, but I need an actual path to the file because I need to make a cconsole command using powershell.exe. The file will look something like this
$/MyTeamProject/MyProject/Development/MyPowershellScript.ps1
Now, I am looking for a vb expression to see if I can get the actual file and make call the powershell.exe command from console. Any thoughts?
You may use VersionControlServer.GetItem(String path) to obtain a reference to the Item. Then use Item.DownloadFile() or Item.DownloadFile(String localPath) to copy the file locally. I have a variation of this that creates a shipment based on multiple changesets.

Visual Studio 2010 Setup does not create added file

My problem should be plain and simple to solve, but google is not helping me today.
I need to read/write a configuration file (config.xml) and, as i see so much problems with permissions with special folders, i decided for myDocuments.
Now, from File system (Setup), I added a custom special folder (myDocuments)
added a subfolder (g1OKweb) inside myDocuments
added the file (config.xml) inside g1OKweb
What I expect, reading around, is that during the installation g1OKweb should be created if not existing or older, and the same for config.xml, but it isn't.
Does someone have any clue?
Thanks in advance
Use Directory.CreateDirectory to create the directory before attempting to access the file. This will automatically create all parts of the path that do not yet exist. If the full path already exists, it will do nothing.
When opening the file, use a FileStream constructor overload that allows you to specify FileMode.OpenOrCreate. This will succeed regardless of whether the file already exists or not.
When you have opened the file, check to see if it is empty before parsing it. If it is empty, insert your XML root element first.

How do I get the path to the associated file used to launch a program?

I have a program with an associated file type. However, when I double-click a file to launch the program, I can't figure out where that path was passed to the program.
Initially I thought the file path would be in Environment.CommandLine, but the command line only contained the program path.
I specified the file association using the Publish Options in visual studio like so: extension: .ext, Description: Some File, ProgId: ProjectName, Icon: SomeIcon.ico.
You are right, it should indeed be passed as a command line argument and be available through Environment.CommandLine.
My guess is that something is wrong with the file association itself. Here is a dated but still useful TechNet article on how these things work. In particular, the "%1" in the screenshot below is essential.
I'm not sure about the DDE thing, so if you're not using it, turn it off.
As a guess, your file type association may not be configured properly. If you look in the registry at your "Open" command for your file type, the command is probably configured as "c:\your-company\your-app.exe", instead of as "c:\your-company\your-app.exe" "%1", which is what it would need to be if you wanted the file path to show up on the command line.