.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

Proper way to encode HTML for Linq insert into DB

Posted By:      Posted Date: October 10, 2010    Points: 0   Category :ASP.Net


I've installed a Free TextBox editor to allow clients to do a write up about themselves and style it with HTML.  Been reading about cross site script attacks (XSS) and want to make sure I'm correctly uploading the data collected with the Server.encode method.

Is this the right way to do it?:

Dim txt As String = TextBox1.Text
            Dim writer As New System.IO.StringWriter
            Server.HtmlEncode(txt, writer)
            Dim DC as new DataClassesDataContext

                Dim c As New Client With {.userID = userGuid, _
                                          .aboutClient = writer.ToString}


View Complete Post

More Related Resource Links

Insert a "Select User" row in Linq for a dropdown list

I'm new to Linq. I have searched and searched the web for a soluion, and can't find anything. I have a Linq query and I want to insert a row ("Select User") to the top before I pass it to the drop down list. I've been trying to use the Union but to now avail (it keeps telling me that my object doesn't support the Union method). My code, prior to attempting to inser a row, is very simple.public SelectList DropDown_Users()        {            var context = new VivarianDataContext();            var query = from t in context.AspnetUsers                        select new { t.UserId, t.LastName };            list = new SelectList(query.AsEnumerable(), "UserId", "LastName");            return list;        }Now I try to insert a row and I found this on the internet and it seems to say that his solution will work. But it is filled with syntax errors. http://magicode.wordpress.com/2009/08/20/inserting-an-item-in-iqueryable-object-using-union-met

Insert html formatted text into word document asp.net(C#)

HI,I am creating an ms-word document from server side using a template. Here i add the reference Microsoft word 11.0 object library. Here i use a template where i set some bookmarks. Now i need to populate those bookmarks.Everything goes fine but i am stuck in one place where i need to write html text exceptnormal text. My code sample is as follows:            object TemplatefileName = Server.MapPath("Template") + "\\High.doc";            object novalue = System.Reflection.Missing.Value;            Word.Table oTable;             Word.ApplicationClass objWord = new Word.ApplicationClass();            Word.Document objWordDoc = objWord.Documents.Add(ref TemplatefileName, ref novalue, ref novalue, ref novalue);            objWordDoc.Activate();            objWordDoc.Application.Visible = true;   objWordDoc.Bookmarks.get_Item(ref prj_name).Range.Text = dProject.Rows[0]["txtProject"].ToString();Here its a complex report. Now in a bookmark i need to write html c

MS Linq To SQL Samples - Insert/Update/Delete

Hi, I'm stumbling along trying my hand at Linq to SQL and have come across this code below that was provided by MS.http://msdn.microsoft.com/en-us/vbasic/bb737928.aspxThe problem is there is no ".add" method for Categories to chose in the statement db2.Categories.add(newCategory)I've seen similar videos here on ASP .NET that uses code very much like the example below, but I am unable to run this example connected to a Northwind SQL database using Web Developer 2010 Express. This is the One-to-Many example listed under Linq To SQL Samples - Insert/Update/Delete. Thanks for any help! Shawn Dim db2 = New DataClassesDataContext Dim ds = New DataLoadOptions() ds.LoadWith(Of Category)(Function(p) p.Products) db2.LoadOptions = ds Dim newCategory = New Category With {.CategoryName = "Widgets", _ .Description = "Widgets are the customer-facing analogues " & _ "to sprockets and cogs.", _ .Picture = Nothing} Dim newProduct = New Product With {.ProductName = "Blue Widget", _ .UnitPrice = 34.56#, _ .Category = newCategory, _

Linq to SQL insert to datatable


I got the following query to group the table. I am wondering how to add a subtotal record with anonymous type.

string prevOriginator = string.Empty;
var oOriginator = (from I in dtIssue.AsEnumerable()
                            group I by new {RaisedBy = I.Field<string>("RaisedBy"), ItemType = I.Field<string>("ItemType")} into grp
                            orderby grp.Key
                            select new {RecType = "D",  RaisedBy = grp.Key.RaisedBy, ItemType = grp.Key.ItemType, Count = grp.Count() });
foreach (var record in oOriginator)
    if (record.RaisedBy != prevOriginator)
        if (prevOriginator != string.Empty)
             //add a subtotal record

How do I retrieve a new row ID immediately upon insert with LINQ?


Hi everyone-

How can I retrieve the row ID immediately as I insert a new record with LINQ? 

I  need to refer back to it to update the row since it will be the only unique data in this particular table ( it's the primary key and the ID  number is auto generated)


HttpUtility HTML Encode


if (!Page.IsValid)
        // Determine the currently logged on user's UserId
        MembershipUser currentUser = Membership.GetUser();
        Guid currentUserId = (Guid)currentUser.ProviderUserKey;

Html column with ListaData.svc + linq + custom webpart

Hello Everybody, 

I'm developing a custom web site with sharepoint, so, I have one custom list that has a html column type. 
I'd like to get this column with linq and ListData.svc, on my custom webpart. But, when I called the method, it's not return this column.

So, my question is:  Can I get a Html column by listdata.svc ?


Insert html tage to sqlserver database through asp.net textbox(asp.net 2.0)


Insert html tage to sqlserver database through asp.net textbox

Display it lable control

Best regards

How to write SQL Insert into query using LINQ


How I can write following SQL query using LINQ. There is no default constraint define for the ID column so we have explicitly pass the NEWID().

I want to replicate the products of a company to another company.

Insert Into Products
Select NEWID() AS ProductID, ProductName, CompanyID = @DestinationID, ProductCategoryID From Products Where CompanyID = @SourceID

Also once I get these result how can I use InsertAllOnSubmit to insert all the records at once without looping it.

need proper LINQ syntax #2


say now i wanna do this type of linq:

IEnumerable<MyStuff> r1 = from ....;

var rslt = from r2 ....
 join r1 ....
 where MyEval(r2.Field1, r1) ... <= #A

Func<Field1DataType, IEnumerable<MyStuff>, bool> <= #B

How do i code the #B ?

should I code it as a variable within the routine, or outside as a routine itself?


How to bind data from linq to html table without a single line of loop.




This is the above code i have worked using querysing and displaying the listitem with in  a simple html table. Here I am using foreach statement to bind items. How to bind the data to a simple html table using SharePoint linq without  a single line of loop.

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Linq;
using Microsoft.SharePoint.Linq;

namespace QuerystringProgramWithoutLoop.QuerystringProgramWithoutLoop
    public class QuerystringProgramWithoutLoop : WebPart
        string strTitle=string.Empty;
        string strStatus=string.Empty;
        protected override void Render(HtmlTextWriter writer)

How to insert dynamic data into an XML or HTML format table


Hi there,

I have a technical problem as the title described. I need to achieve this by SSIS that means the destination file could be XML or HTML. However, before inserting dynamic data from source, an XML or HTML format table must be predefined. In the final destination file, the predefined table and dynamic data will be both output.

Can anybody give some suggestions or reference links regarding to this? Appreciate it.


Help: populate Html.DropDownList from table data? [Linq to SQL model]


I have two tables, Users and Roles.  The roles table is a reference table for the different roles of my site (RoleId and RoleName columns). The Users table contains profile data for each user, including a RoleId column that is FK'd back to the Roles table [RoleId].

Both tables are in a Linq to SQL model.

I have an edit page created which lists all the profile values of a user.  The edit page inherits the User model.  One of the editable values is the RoleId field.  I want to set this up to be a drop-down list that contains items labeled using the RoleName column of the Roles table, and matched with values of RoleId.

How can I achieve this?

Simple LINQ to SQL Insert


I have this:

protected void btnInsert_Click(object sender, EventArgs e)
        lusHmoobDataContext lusHmoobDC = new lusHmoobDataContext();

        lusHmoob lhbLusHmoob = new lusHmoob();

        lhbLusHmoob.wordID = Guid.NewGuid();
        lhbLusHmoob.word = txtWord.Text;
        lhbLusHmoob.usage = txtUsage.Text;
        lhbLusHmoob.hmgTrans = txtEnglishTrans.Text;
        lhbLusHmoob.engTrans = txtEnglishTrans.Text;
        lhbLusHmoob.originate = txtOriginate.Text;
        lhbLusHmoob.modDate = DateTime.Now.ToLongDateString();
        lhbLusHmoob.insertDate = DateTime.Now.ToLongDateString();


And I kept getting this error even though when I compiled, there is no error.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'lusHmoob' does not contain a definition for 'wordID' and no extension method 'wordID' acc

SPMetal: Using Linq to SharePoint Datacontext to Insert Page


I am trying to insert a Page (on a Publishing Site) in SharePoint 2010 using the generated SPMetal classes.

Here is the code that I am using to insert a page:

using (var dataContext = new MySharePointSite1L2spDataContext("http://localhost"))
  var pages = dataContext.GetList<Page>("Pages");
  Page page = new Page();
  page.Title = "New Page";
  page.Name = "Page.aspx";    
  page.Path = "/Pages";

The code results in an NullReferenceException with the details "Object reference not set to an instance of an object."

Stack Trace:
   at Microsoft.SharePoint.Linq.EntityTracker.AddFile(EntityRef eref)
   at Microsoft.SharePoint.Linq.EntityTracker.SubmitNewEntity(NewEntityRef newEref, Stack`1 visited)
   at Microsoft.SharePoint.Linq.EntityTra

How can I insert HTML data in the DB ?



I am new in Asp.net & C#. I am working in a project in which I have to give a textarea (like WYSIWYG editor), where user can put text, images  anything, same as we get in blogs. How I can create that textarea in asp & if I am able to create that type of textarea, then how the content (includes text, images etc) will be inserted in the DB & how it can be retrieve ?

It is same like blogs. Please help me to know, how it can be done in asp.

Thanks in advance...

Client-side HTML Encode and Decode functions with jQuery

The article Client-side HTML Encode and Decode functions with jQuery was added by small peter on Monday, March 21, 2011.

HTML encoding and decoding is used daily by web developers. ASP.NET provide us with build-in server-side functions to perform this job. This article will show you a simple implementation of client-side HTML encoding and decoding functions with the help
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend