Start an Instance of Autodesk Inventor - asp.net

Am Using Inventor api for customizing inventor documents.Here I use vb.net code for start an instance of the Inventor .my code is
inventorApp = CreateObject("Inventor.Application", "")
inventorApp.Visible = True
it is ok and working fine .but when we open the visual studio run as administrator then the createobject having some error.Any one know any other way to start an instance of Inventor?

Try using the marshal method instead.
Dim m_inventorApp As Inventor.Application
Try ' Try to use active inventor instance
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
m_inventorApp.SilentOperation = True
Catch ' If not active, create a new instance of Inventor
Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(inventorAppType)
' Must set visible explicitly
m_inventorApp.Visible = True
m_inventorApp.SilentOperation = True
End Try
Catch
'Cant get or create an instance of inventor.
End Try

Private Sub Open_Button_Click()
ThisApplication.SilentOperation = True 'Suppresses the resolve links dialog
Dim myPath As String
myPath = FileName.Text 'Gets the string, FileName, from module 1
Dim Shell As Object
Set Shell = CreateObject("Shell.Application")
Shell.Open (myPath) 'Opens selected file
Resolve_and_Open.Hide 'Hides module
CompareStrings
End Sub
This is to open a sad assembly that needs to resolve links. I'm not sure if this will get around that error, but try using this:
ThisApplication.SilentOperation = True
Either that, or creating a shell and then opening it that way instead of directly.

Related

How to run Command Prompt commands from VB.NET?

I have an application which build in vb.net.I never learn VB.I have worked on C#.net.when I run it's setup and execute it,I able to see command prompt.But when I using this application for scheduling task/creating task and scheduling, unable to see command prompt.
I am using following code that create process.
Dim Cw As New ProcessStartInfo(name, name & " " & name)
Cw.WindowStyle = ProcessWindowStyle.Maximized
Process.Start(Cw)
Is there is any other way to do this?Without making a process can I execute shell program?I am working on windows8 opeating system
You can use a simply Shell command, so:
Shell(path_to_your_exe, AppWinStyle.MaximizedFocus, true, 1000)
Be careful with path, if you have blanks escape they so
Shell(""d:\folder blank\my.exe"")
MSDN: https://msdn.microsoft.com/es-es/library/microsoft.visualbasic.interaction.shell(v=vs.110).aspx
If I understood the question, you might be using a Windows Form Application and you want to see the command line info of your external application.
In that case, you can use this code:
Sub Main()
Dim ProcessStartInfo = BuildProcessStartInfo("E:\path\to\your\exeFile.exe", "")
Dim proc = Process.Start(ProcessStartInfo)
End Sub
Public Function BuildProcessStartInfo(exeFilePath As String, arguments As String) As ProcessStartInfo
Dim startInfo = New ProcessStartInfo
startInfo.FileName = exeFilePath
startInfo.Arguments = arguments
startInfo.CreateNoWindow = False
startInfo.UseShellExecute = True
startInfo.WindowStyle = ProcessWindowStyle.Maximized
Return startInfo
End Function

excuting cmd prompt through asp.net app, with more than one command line

I'm looking to run a command prompt with a "dir" command in my web app and read the response...which I've got working but I need to to do another command first i.e. I need to use a CD to get to the proper directory.
I can get a DIR response and write it to the screen by basically using this link :
http://weblogs.asp.net/guystarbuck/archive/2008/02/06/invoking-cmd-exe-from-net.aspx
or here is the code:
If Not IsPostBack Then
Dim _info As New ProcessStartInfo("cmd", "/C " & "DIR")
' The following commands are needed to redirect the
' standard output. This means that it will be redirected
' to the Process.StandardOutput StreamReader.
_info.RedirectStandardOutput = True
' Set UseShellExecute to false. This tells the process to run
' as a child of the invoking program, instead of on its own.
' This allows us to intercept and redirect the standard output.
_info.UseShellExecute = False
' Set CreateNoWindow to true, to supress the creation of
' a new window
_info.CreateNoWindow = True
' Create a process, assign its ProcessStartInfo and start it
Dim _p As New Process()
_p.StartInfo = _info
_p.Start()
' Capture the results in a string
Dim _processResults As String = _p.StandardOutput.ReadToEnd()
' Close the process to release system resources
_p.Close()
' Return the output stream to the caller
Response.Write(_processResults)
End If
The trouble it's in the wrong directory...how can I do a CD otherdir first?
Anyone know?
Thanks,
You could try with this command concatenation character
Dim _info As New ProcessStartInfo("cmd", "/C C: & CD C:\TEMP & DIR")
Why so complicated? You can use this one-liner:
string[] filePaths = Directory.GetFiles(#"c:\MyDir\", "*.bmp");
to get an array of all files (in this case, all .bmp-files) in the given directory. The extension parameter is optional.

Can't share isolated storage file between applications in different app pools

I've got various web apps (containing WCF services) in IIS under the default website. As long as they are all running in the same app pool they can access a shared isolated storage file no problem.
However, once I move them to different app pools I get "System.IO.IsolatedStorage.IsolatedStorageException: Unable to create mutex" when one tries to access a file created by another. They are all running under NetworkService user. I tried GetUserStoreForAssembly and GetMachineStoreForAssembly all with the same result. Any ideas why they couldn't use a shared file?
I made sure to close the stream and even dispose it in case one was holding onto it, but I am running a simple test where one service writes it, then another tries to read from it later, and it always fails.
Also, I am accessing the isolated store from a signed assembly.
Does anybody have any ideas?
Here is the code:
Private Sub LoadData()
Dim filename = FullFilePath(_fileName)
Dim isoStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
' Tried GetMachineStoreForAssembly, same failure
isoStorage.CreateDirectory(ROOT_DIRECTORY)
If (isoStorage.GetFileNames(filename).Length = 0) Then
Return
End If
Dim stream As Stream = New IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, isoStorage)
If stream IsNot Nothing Then
Try
Dim formatter As IFormatter = New BinaryFormatter()
Dim appData As Hashtable = DirectCast(formatter.Deserialize(stream), Hashtable)
Dim enumerator As IDictionaryEnumerator = appData.GetEnumerator()
While enumerator.MoveNext()
Me(enumerator.Key) = enumerator.Value
End While
Finally
stream.Close()
stream.Dispose()
stream = Nothing
End Try
End If
End Sub
Public Sub Save()
Dim filename = FullFilePath(_fileName)
' Open the stream from the IsolatedStorage.
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
' Tried GetMachineStoreForAssembly, same failure
Dim stream As Stream = New IsolatedStorageFileStream(filename, FileMode.Create, isoFile)
If stream IsNot Nothing Then
Try
Dim formatter As IFormatter = New BinaryFormatter()
formatter.Serialize(stream, DirectCast(Me, Hashtable))
Finally
stream.Close()
stream.Dispose()
stream = Nothing
End Try
End If
End Sub
Looks like it was a trust issue.
After adding the assembly accessing the isolated storage file to the gac it magically worked as everything in the gac has full trust set automatically.
This works for me, but it might not always be an option to do this for other solutions. Check out the .NET Framework caspol utility if this is the case.
Hope this helps somebody! It was a huge pitafor me.

Is there a macro/extension to set all web projects in Visual Studio to "Don't Open a Page"?

Occasionally, I'm debugging a problem that occurs across several of our back-end web services, and I have them all setup as startup projects; when I hit F5, they all launch new tabs in whatever browser I have set to default at the time -- it would be useful to me to be able to click a button, and have all of the Project > Properties > Web > Start Action settings set to "don't open a page." Anyone know of a macro or extension that might be able to help me out?
I wrote most of the solution for you, except I wasn't sure how to check if a Project is an ASP.NET project or not. One way to do it could be to check whether Project.ExtenderNames contains the string "WebApplication", but I'm not sure that's the best solution.
Sub ChangeAllWebProjectsStartActionToDontStartWebPage()
Dim project As EnvDTE.Project
If DTE.Solution.IsOpen Then
For Each project In DTE.Solution.Projects
NavProj(project)
Next
End If
End Sub
Sub NavProj(ByVal project As Project)
Dim outputPathProperty As EnvDTE.Property
Dim outputPath As String
If Not (project.ConfigurationManager Is Nothing) Then
' It's a project!
Dim extenderNames As String()
extenderNames = project.ExtenderNames
If (Array.IndexOf(extenderNames, "WebApplication") >= 0) Then
project.Properties.Item("WebApplication.DebugStartAction").Value = 4 ' WebStartAction.NoStartPage
End If
Else
NavProjItems(project.ProjectItems)
End If
End Sub
Sub NavProjItems(ByVal projItems As ProjectItems)
Dim projectItem As EnvDTE.ProjectItem
If Not (projItems Is Nothing) Then
For Each projectItem In projItems
If Not (projectItem.SubProject Is Nothing) Then
' Recurse, can be an Enterprise project in
' Visual Studio .NET 2002/2003 or a solution folder in VS 2005+
NavProj(projectItem.SubProject)
End If
Next
End If
End Sub
This is based on the WebStartAction which is defined as:
enum WebStartAction
{
CurrentPage = 0,
SpecificPage = 1,
Program = 2,
URL = 3,
NoStartPage = 4
}

Export SQL database to Access - ASP.NET

Is there any way to export data (not necessarily schema) to an access database via asp.net?
The server has no office components installed and the process must occur via a webpage (like an excel export).
You have to do it programatically.
Open the source table
Create a new AccessDB using ADO Extensions (as shown above)
Create the table in the AccessDB by reading the source schema (CREATE TABLE X ...)
Iterate thought the source table inserting the records in the Access table
Note: Code from http://www.freevbcode.com/ShowCode.asp?ID=5797 posted here in case the link cease to exists in the future
'select References from the Project Menu, choose the COM tab,
'and add a reference to Microsoft ADO Ext. 2.7 for DDL and Security
Public Function CreateAccessDatabase( ByVal DatabaseFullPath As String) As Boolean
Dim bAns As Boolean
Dim cat As New ADOX.Catalog()
Try
'Make sure the folder
'provided in the path exists. If file name w/o path
'is specified, the database will be created in your
'application folder.
Dim sCreateString As String
sCreateString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
DatabaseFullPath
cat.Create(sCreateString)
bAns = True
Catch Excep As System.Runtime.InteropServices.COMException
bAns = False
'do whatever else you need to do here, log,
'msgbox etc.
Finally
cat = Nothing
End Try
Return bAns
End Function
DEMO
====
' If CreateAccessDatabase("F:\test.mdb") = True Then
' MsgBox("Database Created")
' Else
' MsgBox("Database Creation Failed")
' End If
Here is a very detailed article. It is something I stumbled upon, not an approach I am familiar with:
File Uploading to Access Database using ASP.NET
by Faisal Khan.

Resources