Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
aBagorn
Aug 26, 2004
Would it be beneficial for me to attempt to learn C# and ASP at the same time? With some Sharepoint integration thrown in?

Adbot
ADBOT LOVES YOU

aBagorn
Aug 26, 2004

boo_radley posted:

I would recommend starting with C#, transitioning to ASP.NET (fairly quickly if you're comfortable with other languages). Get to know ASP.NET to a good degree before tackling SharePoint. While SharePoint is based on ASP.NET, it's much larger and complex. It also imposes a certain rigor on development that web developers seem to chafe against. Well, it doesn't exactly impose that rigor, but there's a lot of ways that you can really damage a SharePoint farm if you don't know what you're doing and stray away from best practices.

If you want some insight into SharePoint development, start here for the developer's overview and in particular read Microsoft SharePoint Foundation as an ASP.NET Application and the sections in ASP.NET vs. SharePoint: How Development Differs.

Thanks. This will be my first foray into developing, and I've put a little bit of time into C# already (a lot of basics at this point, still learning) and one of my bosses was talking with me about it and said that they would look into budgeting a new Jr Developer position in for me if I felt comfortable enough with the .NET Web side.

Need to get out of help desk hell, you see.

aBagorn
Aug 26, 2004
Ok, so I'm attempting (and please tell me if this is a bad decision) to learn on the fly via several methods, including textbooks, you guys, and my favorite, downloading/browsing open source projects and trying to parse the function of the code.

My C#/ASP is getting there, but now I'm running into SQL troubles.

Not so much troubles, as how to import a .xls or .csv spreadsheet into something I can query with a textbox. I don't need to populate results on the fly (though that would be nice, and I think I know how to do it).

I currently have a spreadsheet from our network engineers that lists all the sites in our company, their assigned egress IP, their range of internal IPs, their router model, and what ISP they use.

I need to build a web app (preferably on SharePoint, as the entire company's intranet is moving in that direction) for our help desk (which I am currently on, and hoping to move out of) to query and filter that data by any of those fields (address, external IP, Internal IP, Router, ISP).

I'm pretty sure I have the code down, I just don't know how to link the data without embedding it (and even my babby's first code rear end knows that's not the way)

aBagorn
Aug 26, 2004

boo_radley posted:

What version of SharePoint are you running? Are you working with your farm admins on this?

2007. And no, I'm on my own for this. This is basically my "if you can do this we'll get you off the help desk and make you a Jr Developer and teach you from there" test.

aBagorn
Aug 26, 2004

epswing posted:

So you don't need the application to actually import these sheets on request? You just need to get the sheets imported once, and write the querying/filtering part?

Actually now that you mention it, the data will need to be updated periodically. That throws a wrench into what I had thought up.

So I guess I'm going to need it to be imported on request from a separate server so it can be maintained by someone without having to get to the code.

This is a little bigger of a project than I originally planned on. Oh well, all the better to be baptized with.

aBagorn
Aug 26, 2004

epswing posted:

You should sit down and design the whole interface first. Get a bunch of scrap paper and a pencil, and literally draw each control on each page. I know it may sound silly, because you kinda know what you want to do in your head, but do it anyways. You'll realize all sorts of extra crap by doing this.

Good call, thanks.

aBagorn
Aug 26, 2004

wwb posted:

The big challenge with getting the user maintained spreadsheet to serve as a data source is "What happens when Bill decides to merge some cells so it prints better?" I'd never take excel as long-term input if I could avoid it.

Anyhow, I fail to see how this could not be accomplished by importing the spreadsheet into sharepoint as a custom list and riding it's built-in search. At least for the first cut.

If I had to write it myself I'd probably look at some crazy search based solution.

Well that's easy enough. Make the data source read only to everyone but me and the NetOps guy in charge of keeping it up to date.

As far as your other question, it probably could, but I want to do things "the hard way" (or at least harder than the most obvious solution) for learning purposes.


boo_radley posted:

As Rooster Brooster said, check out the BDC if you're using MOSS. There are some things that will require you to work with farm admins to get working correctly, though. This work is non-trivial, though.

Here's a decent overview of working with the BDC: http://sharepointmagazine.net/articles/everything-you-need-to-know-about-bdc-part-1-of-8

You're taking on a lot of work for an untrained developer, though. I admire the spirit, but be careful you don't trash servers, etc. Also make sure you're not doing Way Too Much Work in your desire to be comprehensive.

edit: depending on how big your data set is, you may be best off using a custom SharePoint list and just using a datasheet view for manipulation: http://office.microsoft.com/en-us/sharepoint-server-help/sharepoint-lists-v-techniques-for-managing-large-lists-RZ101874361.aspx?section=5

Thanks so so much for the resources.

I realize it's a lot of work, but hopefully (if I don't screw it up) I'll be the better for it.

aBagorn
Aug 26, 2004

Vintersorg posted:

I apologize in advance if this has been covered extensively, checked back the last couple pages and didn't see anything. The OP is a little out of date but it's regarding books.

I am moving from regular old .NET (creating various forms with file i/o, database, etc) to ASP. This is for a Co-Op and while most of the code remains similar (based on the couple days of coding) I want to get a crash course in ASP and have a reference manual. Any recommended books? My teacher said it shouldn't be too much of a big deal but I hate having to rely on random rear end searches. I'll be using VS 2010.

VB or C#?

aBagorn
Aug 26, 2004

Ithaqua posted:

Webforms or MVC?

Speaking as a newbie, which is generally preferred and for what type of web app?

Yes I'm aware I could probably Google this but I'd rather hear some goofy opinions.

aBagorn
Aug 26, 2004
Well, after teaching myself (pretty well, I think) over the past 3 months, I'm getting a 4 day comprehensive crash course courtesy of Learning Tree.

Anyone ever done any of their stuff?

aBagorn
Aug 26, 2004
Ok guys I'm slowly figuring this poo poo out, and thanks for all the help so far.

I just want some feedback as to whether I'm on the right track here.

What I want to have happen is have users populate a text box and then query a db with that text, going over all columns in each record, returning the results in a list.

I woke up this morning with this in my head, would it do what I wanted?

code:
public static List<foo>  GetFoo(string bar1, bar2)
{
    IEnumerable<foo> foos = from foo in db.foos
                            where foo.bar1.Contains == textbox.Text
                            or foo.bar2.Contains == textbox.Text
                            orderby foo.bar1 descending, foo.bar2 descending
                            select foo;
    return foos.ToList();
}

public void Button_Click(Object sender,    EventArgs e)
    {
        GetFoo();
    }
(again I'm sorry for these obviously basic questions.)

aBagorn
Aug 26, 2004

Ithaqua posted:

Well, your method GetFoo takes two parameters, which it doesn't look like you're using, since you call "GetFoo()", and your method directly refers to "textbox.Text". Unless you have an overload of GetFoo that takes no parameters, that code wouldn't even compile.

Couple of things:
1) You might as well leave the return type of your method as IEnumerable and skip the .ToList(). The .ToList() is forcing the query to execute, since LINQ is lazy and won't enumerate your results until it actually needs to.

2) Are you using LINQ to SQL? If so, look at an alternative, since Microsoft has made it pretty clear that Entity Framework is going to be their ORM solution of choice.

Ok I think I'm getting what your saying about the parameters of GetFoo.

As far as 1, so I should just "return foos"?

And as to 2, yeah I am. What would be the difference syntactically?

aBagorn
Aug 26, 2004

wwb posted:

LINQ != LINQ to SQL

Linq is a language concept that is globally useful and translates well to ORMs. One could argue it is inspired by ORMs.

LINQ to SQL was a prototype, grossly over simplified ORM / data layer generation tool that microsoft mistakenly released with .NET 3.5.

This makes me feel better.

aBagorn
Aug 26, 2004
Hey guys, my first app got deployed on the company intranet today!

If you've seen my posts recently, you'll know what a struggle it's been as a complete non developer to try to crash course C# in like 2 months.

But now there's actual concrete evidence that I'm at least able to do this. I want to thank all of you for being so patient with my admittedly dumb questions. So hopefully this is the beginning of my transition from IT to Development.

Now our Sr Dev just told me that he already wants more functionality. Instead of just searching the db and posting the results in a grid view (what it currently does), it needs the ability to select individual records and modify them.

Shouldn't be too hard.

aBagorn
Aug 26, 2004
Another quick question:

Is there anyway I can take data from a GridView row and use it to populate text boxes?

Right now I'm using this code:

code:
var sites = from site in db.SiteLists
                        where site.Site_Address.Contains(searchText.Text)
                        || site.Router_Model.Contains(searchText.Text)
                        || site.Service_Provider.Contains(searchText.Text)
                        orderby site.Site_Address, site.Router_Model, site.Service_Provider
                        select site;
            GridView1.DataSource = sites.ToList();
            GridView1.DataBind();
to query my database and populate.

However for record updates, I want to be able to do something like this:

code:
var update = db.SiteLists.Single(site => site.Site_Address.Equals(addressBox.Text));
            update.Site_Address = addressBox.Text;
            update.Router_Model = routerBox.Text;
            update.Service_Provider = providerBox.Text;
            db.SaveChanges();
How do I select a row from GridView1 and make the data from its colums go into addressBox, routerBox, and providerBox respectively? Google has been pretty terrible in this aspect.

edit:

I have a terrible workaround, and it presents a different problem.

I used a completely new search method to populate the textboxes, and that's all well and dandy, using similar code to the above, but instead of binding it to the grid, I loop through it and populate the textboxes accordingly.

The problem arises when we have sites of similar name (e.g., our bigger sites have 2 separate connections, one for intranet and one for internet), the textboxes will only populate with the first one.

Is there some sort of if statement I can use to check whether the number of records returned >= 2, and provide an intermediate popup that allows the user to select which of these possible records they want to edit?

aBagorn fucked around with this message at 22:02 on Jan 26, 2012

aBagorn
Aug 26, 2004

Ithaqua posted:

I would just like to point out that you've mixed your presentation and data layers together, which is a no-no. Your presentation layer shouldn't have any sort of data access code in it whatsoever.

Luckily, you're using an ORM, so at least it's a little bit better than calling SqlCommands directly from the page.

I'd recommend looking into ObjectDataSource for what you're doing, because I can almost guarantee it will make your life easier. You define an ODS, tell it what methods to call and what parameters to provide the methods for your CRUD, and then it calls those methods as appropriate.

[edit] Check this out! Editable gridviews

If you're using ASP .NET webforms, you might as well leverage the stuff that's built-in.

Ah, cool.

Yeah this is the kind of stuff I need to know.

My code is all over the place, and I'm just worried about "does it work" rather than "best practices", and I should be concerned with both.

FWIW I have 2 WebForms with almost identical data access code on it because I was too stupid to use session data to pass values, and didn't create a new class to contain the data methods cause I'm dumb :downs:

aBagorn
Aug 26, 2004

Ithaqua posted:

You're asking the right questions and learning the good stuff along the way, which is pretty much the best you can hope for. My first production application was a true horror. Write unit tests where you can and don't be afraid to refactor.

Ithaqua I don't want to poo poo up the thread anymore with stupid questions but if you're up for it, I do have more stupid questions.

No PMs but my email is in my profile

aBagorn
Aug 26, 2004
Ok goons ready for more crappy code that will make you cry?

As mentioned before, my app works. I've actually gotten it to work better than I originally hoped, even.

But as it sits there on the intranet, being really useful to the net admins and the help desk, I came back to what Ithaqua had said about best practices, and keeping my data access out of my presentation layer.

So in that vein I decided to rewrite it from scratch as a test to myself.

It doesn't work for poo poo. It compiles ok, but no data gets passed. Using the debugger I can't exactly tell where it's going from the value I have in a textbox to 'null'.

Some relevant code. On the search page, I declare a string variable and then have a button click method.

code:

public string SearchText { get; private set; }
 
protected void searchButton_Click(object sender, EventArgs e)
        {
            NhsSitesData data = new NhsSitesData();
            SearchText = searchBox.Text;
            data.GetSite();
            DropDownList1.DataSource = data.dropdown;
            DropDownList1.DataBind();
        }

The method invoked is in my fancy new data accessor class, NhsSitesData, which looks like this:
code:

public class NhsSitesData
    {
        NHSSitesEntities db = new NHSSitesEntities();
        public Search page = new Search();
        public List<string> dropdown { get; private set; }
 
        public void GetSite()
        {
            var sites = from site in db.SiteLists
                        where site.Site_Address.Contains(page.SearchText)
                        || site.Router_Model.Contains(page.SearchText)
                        || site.Service_Provider.Contains(page.SearchText)
                        orderby site.Site_Address
                        select site.Site_Address;
            dropdown = sites.ToList();
        }

As you can of course gather, what is supposed to happen is the db should be queried according to the text in the searchbox, selecting only the address property of each record, throwing it into a list, and populating a dropdown with that list.

But nothing happens. Not a drat thing. Am I missing something with session info here?

aBagorn
Aug 26, 2004

Ithaqua posted:

:words:

Thank you thank you thank you! It makes so much sense now.

Don't ask me why I was doing it (or trying to do it) the other way before and making it needlessly complicated.

Last question about this project, I promise.

I want to have a popup do a confirm/cancel dialog when a site is updated/deleted/added. In WinForms I would just do a MessageBox.Show and be done with it.

I'm assuming it's not so simple with web. Do I need to use JavaScript?
or something like:

<asp:Button ID="deleteButton" runat="server" Text="Delete" OnClientClick = "return confirm('Are you sure you want to delete?');"/>

aBagorn fucked around with this message at 14:38 on Jan 30, 2012

aBagorn
Aug 26, 2004

Ithaqua posted:

That sounds about right.

Yeah that worked pretty well.

Now for the icing on the cake. Integrating it with our off the shelf ticketing software if I can.

(not completely necessary, but I'm going to try to do it anyway. Who wants to make everyone's lives easier? this guy :effort: )

Edit:

Tiny rant incoming: some smarmy as gently caress douche at the company tells me today, "I don't know why you bothered to code all that, it will be obsolete when we migrate to SharePoint"

Please tell me there's a way to import an existing ASP.NET application into SharePoint so I can shut his smug rear end up.

aBagorn fucked around with this message at 00:35 on Jan 31, 2012

aBagorn
Aug 26, 2004

Sab669 posted:

So, I'm pretty new to the whole "security", thing. I don't take my first official software security class until next quarter, but I'm always down for learning sooner.

I'm working on an online shopping cart sort of application in a .net class I'm taking this quarter, and I have it so people need to sign up before they can purchase stuff. But I'm curious, what's considered the 'proper' way of encrypting passwords in .Net?

I recently "learned how" in PHP (or rather, someone briefly showed me the phpass class), but I wouldn't know how to properly encrypt it when I first add a user to a database, and then when they actually log in compare that to what's in the DB.

Any pointers, goons?

I was just about to ask something like this, but what I want to do is scrape our AD for the information without having the user have to log in (what it should do is keep out all the users except those that are in our HelpDesk and Desktop Support OU, as well as domain admins)

I tried just doing this in the webconfig, doing an

allow roles "domain\ou"
deny users "*"

but that poo poo out errors about my SQL connection string.

aBagorn
Aug 26, 2004

wwb posted:

Disable membership and the role provider. Change authentication mode to windows. Profit.

Profit indeed!

E: was it really that simple? LOL

aBagorn fucked around with this message at 20:53 on Feb 1, 2012

aBagorn
Aug 26, 2004

mintskoal posted:

This. When I started learning it I think I probably said "gently caress this poo poo" 100 times, but once it clicks it's fantastic. Same with MVC.

I'm in the "gently caress this poo poo" phase with MVC right now. I see why it's better, I know it will be fantastic, but right now I'm being a stubborn rear end in a top hat.

aBagorn
Aug 26, 2004

Crankit posted:

I checked the OP but it's 3+ years old, and I think there are newer .Nets than that, could someone recommend a book to learn C# from?

I might get some grief, but I had a great learning experience (albeit from a truly beginner standpoint) with Head First C#

aBagorn
Aug 26, 2004
I suspect I will be very active in this thread and stackoverflow in the near future as I start my dream personal project.

I'm planning on using C# to write a weather simulator, based on input data from the major computer models available for public consumption.


(please tell me I'm not nuts for attempting this)

aBagorn fucked around with this message at 16:02 on Feb 17, 2012

aBagorn
Aug 26, 2004

Gravy Jones posted:

Are you planning on using it to become a supervillain?

Of course.

In reality, no. I just want the program to grab the data from the computer models based on a user inputted date range and then output a simulation of weather conditions (for an inputted location (street address converted to lat/long) ) during that timeframe.

Just your average weather junkie

aBagorn fucked around with this message at 17:14 on Feb 17, 2012

aBagorn
Aug 26, 2004
Ok, what do you guys consider to be the best map API, Google or otherwise, for .NET?

aBagorn
Aug 26, 2004

Ithaqua posted:

That's... retarded. If the end product is going to use a relational database, it should be developed against a relational database for integration testing purposes.

Also, I'd recommend against LINQ to SQL as an ORM solution... Microsoft has pretty much openly stated that L2Q is dead. Entity Framework is actively being developed, whereas L2S is not.

This, exactly.

Find some way to virtualize or grab some old machines and make a development LAN for yourselves (that's actually what I'm doing).

aBagorn
Aug 26, 2004

Ithaqua posted:

Hell, as long as the schema is source controlled and updated as part of each release, there's nothing wrong with having a local SQL instance to develop against. You can even use SQL express at that point, which has a 2 GB database size limit.

Yes I forgot to mention that, which is funny because I'm doing exactly that with an application I'm beta testing on our help desk. The website AND db are both hosted on my workstation.

aBagorn
Aug 26, 2004
Is there a reason
code:
GridView1.SelectedRow.Cells[0].Text
would return null even after the GridView has been bound?

I'm trying to pass the text in the first column as a parameter in a method later.

aBagorn
Aug 26, 2004

gariig posted:

Try checking to see if
code:
GridView1.SelectedRow==null
I'm guessing there isn't a row selected when a GridView is first bound.

e: I got it. I didn't think to account for the cells that contained the autogenerated "select" link in them as [0], bumping all the numbers up 1.

code:
GridView1.SelectedRow.Cells[1].Text
Got me exactly what I needed

aBagorn fucked around with this message at 16:31 on Feb 24, 2012

aBagorn
Aug 26, 2004
Weird question.

I have a Grid View that's populating itself from SQL, no harm there.

There are rows that, by design (not allowed to change it) have certain columns that have empty string values ('') (why they didn't use NULL, I will never know).

When selecting the Grid View for editing the values, I'm populating dropdowns and then defaulting the selected value to what's in the cell.

I tried to do a

code:
string primary = GridView1.SelectedRow.Cells[2].Text;
if (!String.IsNullorEmpty(primary))
   primaryDrop.SelectedValue = primary;
but that threw an exception with the cells that had an empty string. When I ran through the debugger, it told me that, in fact, the cells that were populated from the SQL empty string now have a value of
code:
"&nbsp;"
instead of the "" I expected.

I could hard code it like:
code:
if (!primary.Equals("&nbsp;"))
    primaryDrop.SelectedValue = primary;
but that seems messy, and doesn't answer my question about why the cells are getting populated with the non breaking space instead of an empty string.

aBagorn
Aug 26, 2004

PhonyMcRingRing posted:

GridView/BoundFields automatically html encode any data by default, you have to turn it off(I think on a per-BoundField instance). For whatever reason, though, WebForms sees an empty string value as something to be converted to  , probably due to old browsers not displaying a table cell if it doesn't have any content in it.

Ugh. I'll try this workaround.

aBagorn
Aug 26, 2004
Hey kids, quick formatting question here.

In the course of one of my WinForms applications, I need to display the MAC address of the computer's various network adapters in a textbox.

This code works fine in getting the string:

code:
        public string AdapterAddress (string criteria)
        {
            adapteraddress =
                (
                    from nic in NetworkInterface.GetAllNetworkInterfaces()
                    where nic.Name == criteria
                    select nic.GetPhysicalAddress().ToString()
                ).First();
            return adapteraddress;
        }
but it outputs as
code:
003E4B880D01
as opposed to
code:
00:3E:4B:88:0D:01
like it would be shown in a command line "ipconfig /all"

I know I need to do something with taking the individual bytes and then joining them with String.Join(":", blah blah) but I can't quite get it.

edit: I found a messy way to do it:

code:
public string AdapterAddress (string criteria)
        {
            adapteraddress =
                (
                    from nic in NetworkInterface.GetAllNetworkInterfaces()
                    where nic.Name == criteria
                    select nic.GetPhysicalAddress().ToString()
                ).First();
            var tempaddress = SplitMacAddress(adapteraddress);
            adapteraddress = tempaddress;
            return adapteraddress;
        }

        public string SplitMacAddress(string macadress)
        {
            for (int Idx = 2; Idx <= 15; Idx += 3)
            {
                macadress = macadress.Insert(Idx, ":");
            }
            return macadress;
        }
I'd still be open to cleaner solutions.

aBagorn fucked around with this message at 19:39 on Mar 5, 2012

aBagorn
Aug 26, 2004
BitConverter is awesome, thanks guys!

aBagorn
Aug 26, 2004
Cross posting in case you guys want to take this:

Our help desk needs internal (NAT) IP info from users to do their (our) thing. Windows 7 doesn't have a GUI for this, and our end users think the command prompt is the boogeyman, so I threw this together:

View: http://pastebin.com/v8FkvK6r
Logic: http://pastebin.com/Mi5PCnvk

(Note, if you find anything really nasty in there, let me know so I can change it and become better at this)

aBagorn
Aug 26, 2004

Ithaqua posted:

Some nitpicky things:

:words:


Nitpicky is good. I'll look over this tomorrow

aBagorn
Aug 26, 2004

Ithaqua posted:

:doh: I wasn't thinking of that. You're right.

Thanks guys, made the switches and it does look a lot cleaner now.

And yes, I'm very guilty of unnecessary properties. This is because I never follow my plan for the project once I start getting into the code. This is a very bad habit

aBagorn
Aug 26, 2004
Ok, was talking to a Java programmer, and referenced the project I just did

View: http://pastebin.com/v8FkvK6r
Logic: http://pastebin.com/Mi5PCnvk

and he had some questions that I didn't have the answer to, and I was wondering if you guys do.

myfacebookJavafriend posted:

so anyway, does it make sense to write queries that are that similar over and over again for each of the 3 or 4 or 5 pieces of data that you want, or can you query multiple pieces of data and then just cache them in some struct and then just pull them from the struct?

it would potentially improve performance

and (although not as much of an issue for something that doesn't change often, like a list of network connections) keep the data from getting out of sync. what if the underlying data changes while the form is populating? say, between pulling the IP address and the gateway address, a new network connection opens up? you'll have more gateway addresses than IP addresses

Adbot
ADBOT LOVES YOU

aBagorn
Aug 26, 2004
Ithaqua, that code worked, by the way.

Talking with this Java guy is actually helping me much more than I thought.

He keeps asking me "can LINQ do this? how would you do that?" and I'm trial and erroring my way through his questions and learning stuff I wouldn't have thought of.

  • Locked thread