I'm working on a project and I'm fairly new to ASP (not to C#).
We have a solution for a whole web application consisting of several projects and I want to add a couple of ASP WebForms to one of the projects. However, when I right click on the folder of the project and select Add element, it only shows me VB options.
But if I try to add other project to the solution, then all the other options are displayed.
The project in which I'm trying to add new Web Forms is entirely written in C#, so I don't know well what's happening back there. I cannot stop thinking it might a dumb mistake I'm making.
I'm working under Visual Studio 2017 and .NET Framework 4.7.2. It is there some kind of requirement I'm missing?
Thanks in advance for your time and sorry if it's something simpler, but I really don't know what's going on here.
As noted, this looks like that one application was created as a vb.net application.
You can freely consume say c# code (assemblies) in a vb.net project. And of course you can do the reverse.
However, for a given project created? You can't at the IDE level mix vb.net and c# code modules and general writing of code between c# and vb.net.
However, as in your example, you can certainly "include" multiple mixes of vb.net and c# projects into one same project. However, each part and section will still be limited to the chosen language used to build that application. So mixing is allowed at the project level - but not below that level.
So, it looks to be that project was created and developed with vb.net. You can't really change that unless you create a new project as c#, and then pull in all the forms, code etc. and re-factor the vb.net to c#.
So your practical project language choice is really limited to the project level. Multiple projects of different languages can be included overall, but each part will remain in its given language choice. The fact that you can do this in .net is amazing enough, but that language choice is really set in stone at the project level.
While you're figuring it out, if you need to press on and get some work done just copypaste another file that is already in the solution, and is of the type you require, then change its contents. This can usually be a time saver anyway, as the "new product" form isn't so hugely different from the "new user" form, just a different bunch of labels and textboxes..
There is nothing magical about the "add new item" dialog, it just adds files with pre filled templated content. For a cs class (for example) that's a file that basically has a detected namespace and the name you specified in the add dialog. You could even add a VB file of the type you want and then change the contents and name of the file to be right for C# - it would essentially be adding a couple of curly brackets and changing the case of Namespace and Class (and maybe changing Imports to using)
You cannot mix languages in the same assembly in .Net. Create another assembly you can put your C# code in there and use it in the VB.Net project.
Or use VB.Net it's not that bad.
Related
I am still getting used to working with c# and wpf. I have made a number of smalls apps to do single tasks. To give the same feel to the apps my company uses I use the same logo, colours and layout.I am also developing a project settings class to save the project variables to file using a json file ( I hope ) and a slide out panel to give the user access to the project variables.
It would make sense to save this as a sort of template / base project so that every time I start a new project I can use this base project to shortcut the workload but every time I to do this I get errors. I have read about class library but am not certain if the is correct way forward or should be some sort of template.
Can someone explain if want I want to do is possible in wpf and what is the correct way forward please. Any questions on here (this site) assumed a bit too much knowledge for me and I can't get my head around the msdn references. So any good links would be helpful
Thanks
In Visual Studio, once you have the basic solution template that you want.
File->Export Tenplate.
Create a new Project Template.
Or if you just want to create a reusable theme. Create a class library and put some ResourceDictionaries inside with your styles and templates, etc. Then reference it from each new project and import the resource dictionaries. This solution would probably be easier to maintain over time as you could easily replace the referenced DLL with a new version when you make changes to the common UI theming.
Before telling you anything i'd like to clear, I'm a completely beginner in ASP.NET. In fact, I started learning today ASP.NET.
So, I'm making an event that would bind my code with C# files. Well I'm good in C#.
But the problem is as I find into projects, there is no Default or any aspx.cs files here. Can you please help? Where can I find it?
This tutorial says that to bind events, you need to write code in .cs files.
Here is my how my project is setup:
I think you have choosen a wrong project type while creating your project.For your purpose you need to do following
File>New>Project
On the left panel Go Visual C# > Web
Select ASP.NET Web Forms Application
Looking at your screenshot it seems you selected "ASP.NET Empty Web Application".You can add files to this as well but since you are a beginner its better to follow above steps.
We have created our website on ASP.NET with C#. But another developer has created her code on VB.NET. Now we have to integrate her pages and code with our existing application.
You can't use VB and C# together within the same Web Application project. What I would recommend is that you convert the VB to C# (or vice-versa) using one of the many automated conversion tools that are available (Telerik has one, for example). Barring that, your next best bet would be to keep them as separate projects and deploy them together to the same site, if that's an option (for example, if each project will be able to have its own set of URLs). If that isn't an option, then you will simply have to bite the bullet and convert one language to the other.
For web application project:
asp.net web application with c# & vb.net both in codebehind
As mentioned by OP in comments, s/he is asking for Web Application projects; so the below is only for website projects:
You don't need to do anything. Just add those .aspx and .aspx.vb pages in your website project. If you are using .NET Framework 2.0 or above, they will compile and the complete website will work.
By the way, if you see, every .aspx page contains the Language attribute in #Page directive which specify the language of the code beside file.
I need to create a simple application that would generate reports based on database data and some user input. I have vast C/C++ experience, but for this project we had to choose C#.
I want to avoid using 3rd-party components that would require installation on a client machine as much as possible. Thus, I would like to avoid using even the features provided by MS Office (I could have used an XLS template, just like my predecessor did, but it doesn't look like a way to go; anyways, my predecessor's sources are long lost, which is probably good, since it is a roughly 10-years-old VB monstrosity that crashes every now and then). The same goes for crystal reports and whatnot.
My current idea is to build HTML tables (using an HtmlDocument) on the fly, to present them to the user (using a WebBrowser) and to print them. Is it a right way to go? Are there any simpler/more robust/better approaches? What are the possible pitfalls?
Building tables on the fly would work. I use that technique every so often, but it seems like a hack to me. I only use it because quite often, the business need requires "good enough" and quick turnaround as opposed to "beautiful".
I'm going to preference what I'm about to suggest bysaying that I have a strong bias against 3rd-party components myself.
I flat out refuse to use them in most cases and will go out of my way to come up with another solution, because I've been burned on upgrades/licensing too often.
That said...
Fortunately, with .NET not all 3rd party components need to be installed to your clients PCs. With XCOPY deployment, often you can just reference a .DLL or a project in the solution ans specify the "Copy Always" or "Copy if newer" option to just include the dll (or resulting dll if you're referencing a class library project) and as long as the .dll is present in the same directory as the executable, the 3rd party component works.
With all of that in mind, there's a project that I've used to print a DataGridView from Windows Forms at CodeProject. This is one that you can get the source for, reference it, and use it without having to actually install anything at the client. I've used it in more than one app, and it's one of my favorite tools.
It will print ONLY the DataGridView, but it prints it exactly as it appears on screen, so if that's what you want, I'd recommend at least checking it out.
As a third option, you could consider using ASP.NET. If you're going to be generating HTML, it's just as easy (easier actually) to do it using ASP.NET than in a WinForms app. Using ASP.NET you get Repeaters, ListViews, etc, all of which make the reports easy to create.
I've got more than one real-world app that is primarily a WinForms app but has an associated reporting site.
For example, I have a WinForms app used for scanning coupons accepted at our retail locaitons. It's a WInForms app because I need to interact directly with the scanner on a COM port. However, for the reporting portion, I set up an ASP.NET website. In the WinForms app it's very simple to create a reporting menu option and point to the pages. Our users generally don't even think about the fact that this is two distinct applicaitons. They see it as one - their Coupon Scanning app.
The point of all that is that it's usually possible to do things with any given tool, but it's far easier to use the tool that is meant for the job. If you're going to be generating HTML reports, ASP.NET is a better tool than building the reports manually, and if you need to have a WinForms app for most of the UI, you can still do that and use the website for the reports - using the best tool for each task.
Maybe you would like to check RazorEngine, to create your HTML templates.
I recommend you Razor engine to render html, it is more flexible than working with HtmlDocument objects.
You can create a file with your report template, and then parse it sending a Collection of your report rows objects.
I've been converting all kinds of other things, classes, interfaces, ASP.NET MVC apps, and WPF applications, but I am stumped as to how to convert a windows forms application, as the whole structure seems to be different. Does anyone have any advice on how to tackle this problem?
I see essentially that you have two files, Form1.cs and Form1.Designer.cs. Literally translating them from C# to VB doesn't work because of some intricacies or other of how Visual Basic works. I think you /might/ be able to convert Form1.cs in this way, as it's just a constructor plus event handlers, but the designer contains the references to the controls etc. and I am not sure how to go about doing that.
I am using Visual Studio 2010 Beta 2.
My approach would be to create a new form in VB do add some forms and add events and look at the VB generated from there you will be able to see how each element [control/event/propertyset] is done in both C# and VB. From there it should be trival to conver from c# to VB.net. This would give me more confidance the designer could cope with the converted class as well as the runtime.
What I did is to manually create a new form in VB with the same name as the form in C#, then opened the C# form in design view, made sure that I selected all controls on the form, copied and pasted them onto the empty new form in VB. Then just translated the code-behind with the telerik free converter at:converter.telerik.com. I'm sure it becomes cumbersome if you have a huge solution that you need to convert, but in my case it was a small solution and the results were great.
Redgate.NET Reflector does a great job.
The two files each contain a part of the Form1 class, in the form of partial classes. As partial classes are also supported in VB.Net, I don't see a problem here.
The designer file contains all of the code generated by the windows forms designer, the Form1.cs file is the place where all custom code goes (event handling, etc).
So after converting both files you should check if all references made to controls in the Forms1.cs file are available in the designer.cs file.