Sharing files in C# on visual studio [duplicate] - c#

I want to import an enum class (.cs) into my project that is generated by another service. So if that service will update this file, it should be automatically updated in my project. It has to be text-only (so I can't use an assembly) because we can't compile code in php.
And here is why I want this:
We are using global language strings in multiple applications and I would like to use them as enumerations for some reasons. When new texts are added I want to be able to use them without copying or changing anything. Maybe there is another way to achieve this.
Thank you.

You can add a source code file to a project as a link.
To do so:
Right-click project and select "Add -> Existing Item"
Navigate to the file you want to add as a link, and select it.
Look at the "Add" button at lower right of the "Add Existing Item" dialog. It has a little drop arrow. Click that drop arrow.
Select "Add as link".

Follow the setps:
Right click on the project go to Add
Select Existing Item
Select the file
On the Add button click the drop down button and select "Add as a Link"

Lets say I want to add a csv file to a project.
Right click on the directory in which you want to add.
Click on ADD and then Existing Item
Click on Add/Add as link , also if you are dealing with csv files or files which don't have convention extensions select All Files in that case.

Related

What is the meaning of C# with shortcut icon appears in visual studio 2010?

Working on some legacy codes - what is the c# class with black arrow overlay
icon in visual studio 2010 and why it appears?
It means that you have a link to an existing item.
This technique is used when you want to share code.
When you edit the file with the described Icon, it also changes the source where it has been linked from.
Edit: To create a link to an existing item: (taken from MSDN)
In Solution Explorer, select the target project.
On the Project menu, select Add Existing Item.
In the Add Existing Item dialog box, locate and select the project item you want to link.
From the Add button drop-down list, select Add As Link.

how insert form from project other in visual c#

I have a Project in which there is a form that has several objects (controls) in itself. I want to add this form to another Project in another Solution. How to I can do this. Thanks.
This is a good thing to reuse your code :)
You have to make a library project.
1)File => New Project
2)Check Visual project in the tree
then select "Class Library", give it a name "MyFormLib"
3)Then simply copy paste YourForm.cs and YourForm.designer from your app project, to "MyFormLib".
4)Now go to solution explorer, browse to your application project, right click on "references" then "add reference"
5)To finish click on "solution" then choose your library project "MyFormLib"
.
6)You can now use the form from the library project inside your application project.
e.g : new MyFormLib.TheForm()
7) To reuse your form in your second application, redo steps 4 to 6
Just simply open the project where you want to add the existing form:
Right click on the Solution Explorer
Select "Add" -> "Existing Item..."
Browse your other project's folder, and search for the 3 files of your form:
yourForm1.cs, yourForm1.Designer.cs, yourForm1.resx
The simplest way is to
Open the destination solution in Visual Studio.
On the Solution Explorer, right-click the destination Solution name and Click on Add > Existing Projects. Identify the project with your source Form.
Move the form from source to destination project (The designer and resx files will move with it)
Change relevant namespace specifications and then you may remove the old form.

C# access files from another project

I am having a solution consisting on silverlight and web project. i want to access a file which is located inside a folder in web project from my silverlight project.how can this be done.
this file is a users manual document for which i have to provide the download functionality to the user..
Right click on the Silverlight project and select Add --> Existing item.
In the dialog, navigate to the location of the web project. Select the file(s) you need but instead of clicking on "Add", click on the dropdown next to the Add button and select "Add As Link".
In your Silverlight project:
Right-click References > Add Reference.
On the left tab, select Solution.
Select which project(s) you want to include a reference to.
In Silverlight project C# files, you may have to add a 'using' statement if you are trying to use a Class from a referenced project.
Got the solutions as below,
var uri = new Uri(Application.Current.Host.Source, "../DirectoryName/FileName.docx");
HtmlPage.Window.Navigate(uri);

c# Add As Link not working (always copies to Project folder?)

c# VS2008 SP1
right Click on Project name, Add Existing Item, selecting Add As Link from the drop down menu, and selecting a .cs file outside of the project folder, causes the file to be copied locally within the project folder.
This is surely not the correct behavior?
Right Click on Project name, Add Existing Item, selecting a .cs file outside of the project folder AND THEN Add As Link from the drop down menu.
That is the default behavior. Also confirmed with Visual Studio 2010
Doesn't do that for me. Are you selecting the file you want first, and then selecting "Add as link" in the weird dropdown button?

Add codebase as reference instead of copy Visual Studio

This may be a ridiculous question for you C# pros but here I go. I'm a Flash developer getting started in Silverlight and I'm trying to figure out how to create a "codebase" (a reusable set of classes) for animation. I'd like to store it in a single location and reuse it across a bunch of different projects. Normally in Flash I would add a "project path" reference and then start using the code. My question is, how do I add a folder to visual studio so that I can "use" those classes in my project. I tried "Add > Existing Item" but that copied the files into my project directory.
The easiest way would to create a new ClassLibrary project and build it. This will output a .dll file in a folder you can specify in the project settings menus, which you reference from every project that needs it.
Also, you can copy this .dll into the /bin/ folder of your project - this will do the same thing for this specific project, but when you start the next one you can change some details in the codebase library without breaking the first project.
The solution described by Tomas (adding a reference to a dll binary) is the correct solution to this problem; better than referencing the source code and compiling it into each project.
But just for extra information, if you ever do need to add a source code file to your Visual Studio project without having it make a copy of the file you can use the following steps:
Right click on your project in Solution Explorer and select Add -> Existing Item.
Navigate to the location of the source code file and select it.
On the "Add" button in the dialog window there is a drop down arrow. Click this and select "Add as Link".
This will allow you to use this source code file in your project without having VS make a copy of the file.
In Solution Explorer, right-click on the project node and click Add Reference.
In the Add Reference dialog box, select the tab indicating the type of component you want to reference. (for instance for a class library a dll)
Select the components you want to reference, then click OK.

Categories