I have created a formula for my application. I know that there are many decompilers to break my application, I want to call a class file from my server and save it in my destination path like C:\test\Formula.cs and call it from my exe file where it is located from
C:\Users\Administrator\Documents\Visual Studio 2008\Projects\WindowsFormsApplication8\WindowsFormsApplication8\bin\Debug\myApp.exe
Similarly, since you can read a text file like this:
StreamReader reader = new StreamReader("C:\\test.txt");
I want to read my class like this:
Class readerclass = new Class("C:\\test\\Formula.cs");
Any help is appreciated.
You can't do that. C# is a compiled language! You can't just pull the source down and try to run it. To do this you would have to compile it on-the-fly and read in the resulting assembly, etc. It would be a disaster.
Now if you had compiled assemblies hosted on the server, you could theoretically download them, load them with Assembly.LoadFrom() and then instantiate classes from that.
You have to either create a library project that contains the formula.cs (dll) or include/add this formula.cs file into your current project.
Related
Is there any tool available to read or explore the solution components using solution file?
OR
Is there any class in Microsoft Dynamics CRM 2011 SDK which take the solution zip file as input and then I can simply use its properties/methods to read/validate the contents and components of the solution file?
For validation, there are several schema files within the SDK, one of them being the CustomizationsSolution.xsd
http://www.microsoft.com/en-us/download/details.aspx?id=24004
For reading the web resources, you can look directly within the "WebResources" folder or by scanning the "solution.xml" file.
Both of these will require unzipping.
There is a SolutionPackager.Exe tool in the SDK that will take an exported solution file and expand it out to directory with all of its components in separate files. I don't believe it has a public interface to call from other code - you would have to read the contents of the directory it creates to discover and read each section.
The XML Schemas (as #Paul Way states above) are available in the SDK. If you build C# classes from these - using xsd.exe in VS - you could (after unzipping the file) load the XML into a strongly-typed classes. This would get you close to what you want - but not exactly.
You want to be able to call something similar to var solution = CRMSolutionTool.LoadPackage(#"mysolution.zip") and then execute a foreach (var item in solution.entities){}. Unfortunately, no one has built such a library at this time.
I'm using MS Visual Studio Pro 2012 and I want to create some kind of help file.
I was thinking in create a html file like this but my question is: Do I need to have the html file always in this directory, even after I have the .EXE file created or the html file is added to the .EXE file?
If not, how can it be done?
[.NET Framework 4.5 | Windows Forms]
EDIT : I want to load a given (local) html file in the default web browser. This file should be 'inside' the .EXE file.
If you're looking to build a help file from Visual Studio, why not look at:
http://shfb.codeplex.com/
Sandcastle will build your help file based on the comments you have written on your classes and methods. Hit the forward slash three times (e.g. /) above your class or method declaration and the comment box will appear. Populate with salient details, run Sandcastle, and your help file will be generated.
The advantage of having a separate HTML file is that you can update it on it's own without pushing out a new assembly. However if you want to build it into the EXE, you can go to your project properties, then click on Resources. Add an existing file (your HTML file) and it will now be accessible from your code.
When you want to open it you can do something like this
string html = Resources.MyHelpFile;
if (!File.Exists("tmpHelp.html"))
{
using (var tmpFile = File.CreateText("tmpHelp.html"))
{
tmpFile.Write(html);
}
}
Process.Start("tmpHelp.html");
You can then delete the help file at a later stage such as when the user closes your application.
I'll recommend using HTML Help Workshop to create the help file. and then use Help.ShowHelp();. Its a lot more easier
But for your case. You can either do as KeyboardP suggested or move the file to your bin/Debug folder and then use
Process.Start("helpname.html");
NOTE : You'll also need to add the file to the Application Folder when you're creating your setup.
You can build html file (I think the most easy way it's to create it via microsoft word and to save as html)
Then you make a new form contain webBrowser tool and set the URL to your html file path, like this:
string filepath = Environment.CurrentDirectory + #"\Help.htm";
Uri uri = new Uri(filepath);
webBrowser_Help.Navigate(uri);
I've put 3 especially large SQL queries within my Visual Studio project, under a folder "Queries" that is in the project directory (not the solution). Is there an eloquent way to access these files? I was hoping that something like #"Queries/firstSqlQuery.sql would work.
Specifying the full path, like with #"C:\\Users\John\Documents\VisualStudio2010\Projects\MySolution\MyProject\Queries\firstSqlQuery.sql
is something I'd really rather not do, since it requires me to go back into code and fix the path, should the application move.
EDIT: For some reason, the page is looking for the files in C:\\Program Files(x86)\Common Files\Microsoft Shared\DevServer\Queries\firstSqlQuery.sql. Why is it looking in this location, when the executable directory is different?
You can do something like this... if it's outside of project. (When I intitially read this-- I misread and thought it was in the solution directory which I was assuming contained the project)--
var pathToBin = Assembly.GetExecutingAssembly().Location;
var directoryInfoOfBin = new DirectoryInfo(pathToBin);
var solutionDirectory = directory.Parent().Parent();
var pathToSolution = solutionDirectory.FullName;
but this is much simpler if it's in the project
System.Web.HttpContext.Current.Server.MapPath("~/Queries/firstSqlQuery");
There are a number of ways to handle this, but there is a fundamental understanding you must gather first. Issuing something like #"Queries/..." isn't, by itself, isn't going to do anything. You need to leverage the System.IO namespace to perform IO operations.
With that part of the foundation, let's lay some more, when you issue a command like this:
File.ReadAllText("firstSqlQuery.sql");
the path that is implied is the Working Directory of the assembly that's executing the code. When debugging an application in Visual Studio, especially and ASP.NET Application, that's the bin directory that resides under the project directory, by default. So, if you did want to access the Queries folder, you would have to do something like this:
File.ReadAllText(#"..\Queries\firstSqlQuery.sql");
so, that's one way of handling it.
Another way of handling it would be to copy the file over into the bin folder every time the project is built by looking at the file properties (e.g. create a Post Build Event), but that's more work than I think you're looking for.
Again, the key here is to understand what directory you're starting in.
Finally, one thing worth noting, if you leverage the directory structure you'll need to ensure that the Queries folder gets deployed to the live site. That probably goes without saying, but I've seen people run into that exact problem before.
You could make sure your query files are copy to the output directory when you do a build and read the files from there without having to set a path.
so what I'm trying to do is open a file (well, actually two folders, but I figure I'll start with a single file for now) using a third party comparison tool called UltraCompare. I'm working in a C# website project in Visual Studio 2010 (Express edition). I've seen how to open a file using a different program, here: Open a file with Notepad in C#.
Problem is, this only lets you open it using the default program for that file type. But I want to open it in a specified program. For example, a text file should open in UltraCompare, not notepad. Here's the code which does this:
string textBoxContents1 = TextBox1.Text;
Process.Start(textBoxContents1);
The textbox on the webform accepts a string, in which the user types the file's full path (not the most user-friendly design I know, but I'm not sure how to allow them to browse for a folder using a GUI interface in asp.NET). The file is then passed into the Process.Start() method, which opens it using the default program for that file type.
Is there any way to modify this to make it open using UltraCompare??
You can specify the program you want to open the file in:
Process.Start("yourprogram.exe", textBoxContents1);
Update
To open two files in Ultracompare, you'd probably do something like that:
Process.Start("yourprogram.exe", "file1.txt file2.txt");
Keep in mind that the second parameter of Process.Start method are the arguments passed to the program.
I said this is probably going to work because I assumed to be very likely that Ultracompare expects 2 arguments, but this might not be the case.
Quick question: Are you trying to do this for the client machine? Hope not
And I guess it looks into the PATH variable for finding your exe
Is there a standard way in .Net to access and modify the windows services file? Right now I'm just accessing the file via a stream and writing to the file like I would for any other file. The file is located in c:\windows\system32\drivers\etc\, but I'm worried that this may change in 64 bit versions of Windows or may vary in different versions of Windows (I could be wrong and admittedly, I haven't looked into this very much yet). Aside from that, I'm just wondering if there is a standard way, say via WMI and/or the System.Management namespace, to find and modify the services file.
The actual specifics of what I need to do is to check if certain database aliases used for our software are specified for the expected ports. If not, add them.
An open source project called System.Peppers has a class doing this.
There is a registry key that contains the full path to the files you are editing.
Here is a link to the exact class: HostFile class
Use the System.Management.Instrumentation namespace
Sample code here
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=114
you can use System.Environment.SystemDirectory to get to the sys32 folder