Posts

Showing posts with the label c#

Host Angular app INSIDE C# Web Api 2 (as single app) (not .Net Core) and install in server (and browse from outside)

Image
Host Angular inside ANY C# / ASP.NET solution. Table of Content: Web Dev Tools List Create DB (ms-sql) Create API (c# webapi 2) + connect to DB Create Angular project  + connect to API Host the NgApp inside the API Install in Server + connect from internet 1. Web Dev Tools List The list of tools : they are all "Next,  Next, Next...", and they are all on google search, SSMS - Sql Server Management Tool - for SQL (also installs server) VS22 - Visual Studio 2022 Community - dont forget to check Asp.Net dev tools with .Net framewroks 4.6.1-4.8 VSC - Visual Studio Code NodeJS (version compatible to the angular version) Angular (your version) For server install - windows server (2022) with IIS 2. Create DB Open SSMS (type "SQL" in start) There, copy your server name (before click "Connect"): Create a DB and a Table (just right-click -> "New..." and give names) Make sure you have an "Id" columns that is key identity, by double-clicking the ...

3 Simple ways to retrieve generic SQL data with C# / WebAPI controller (using DataRow)

Image
Full Code in the end! :) Assuming you have some connection string: private static string ConnectionString = ConfigurationManager.AppSettings["myConnStrApp"]; And assuming we are using the simple "SqlDataAdapter", our Method will start with: using (SqlConnection conn = new SqlConnection(ConnectionString)) {       using (SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM " + tblname, conn)) {             DataSet ds = new DataSet("ds");             adp.Fill(ds); We have 2 generic options return (convert to) Json String build json object Lets 1st mention the "standard" way - by class model. That means we need to create a new C# class per sql table, and then create matching parsing mechanism, meaning that the rest of our method contains this (see more in the end): var rows = ds.Tables[0].Rows; for (int i = 0; i < rows.Count; i++) {     var r = rows[i];     t.Add(new TNG() {     ...

Python vs C#, a REAL answer

Python vs C#, Dynamic vs Static, Imperative vs. Declarative, Compiled vs. Interpreted. and each philosophy. which also puts the design of the language, and open source or not, cross-platform. ohh and lets not forget Strong vs Weak. these are the real comparisons you need to thing about when thinking c# vs python. so lately i'm getting more and more interested in python, for many reasons, it being open-source/linux oriented, its power and ability to be a script and therefor its loved by hackers (i mean pin testers lol), dynamic, ect. ect. problem is that googling something like "C# vs Python" or "why python is better that C#", most answers, including stack, will result in "its more fun", "its dynamic", "less code", "free", "Microsoft is the evil spreading and we must fight it". well, as all that may be true, its not the reason why python is better, but why would I as a programmer would like to start usin...

FormData, send file with ajax, send ajax with a file, explanation, tutorial, and example, in c# asp.net

so... this will be the table of content for everything i wrote in this long, long title FormData simple overview the most simple way to define it is, as simple as that, do a full postback without a postback, just with ajax. usually you'll need it in 2 scenarios - (a) uploading file/s, maybe with other properties. (b) security won't let you do JSON. so what i made for you? 1. Detailed simple explanation about the examples in developer.mozilla.org docs, its a bit hard to get examples . 2. Detailed simple explanation and example about how to make it more JQuery and generic 3. Simple explanation and example about how to use it with a C# handler HF!!

Detailed simple explanation about the examples in developer.mozilla.org docs, its a bit hard to get examples

have you read this  https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Submitting_forms_and_uploading_files ? or the more basic one  https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects ? a bit hard and un-copy-pasteable. after that you may read my own a bit more generic exmamle . so lets start with the 2nd link , which is supposely simple, but there are a couple of catches. 1st, although it says, you can only create a FormData with a form element, which is a bit problematic in many cases where you can only have 1 form like in asp.net or sharepoint. the solution will be presented down here with the explanation about the upper link, and in a more generic example in my other post here 2nd is in the jquery example, where they say you can turn off the proccessData and contentType, which although true, but that means you need to break the request hardcoded, and that in managed frameworks you'll get the raw st...