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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

What Am I Doing Wrong? (URGENT XML and LINQ)

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

Hy Guys,

I need to parse a complex XML file, so I decided to do that using LINQ with xDocument.

I've done everything that (I think) is needed and, when I execute the aspx file, nothing happens. Debuging it, there's no one error, but the returning is always nothing. On debug mode, I see that de XML file is right loaded, but my code is unable to find any node and value using linq.

Below you will find the code that I'm using and also a little part of the complete XML file. On this code, I'm just trying to get few nodes values for example in this forum, but on the real code I will need to get all XML information.


  XDocument xmlFile = XDocument.Load(@"C:\TESTEnfe.xml");

        var a = from c in xmlFile.Descendants("nfeProc").Elements("NFe").Elements("infNFe").Elements("ide")
                select new
                    cUF = c.Element("cUF").Value,
                    cNF = c.

View Complete Post

More Related Resource Links

Urgent How to Create it ,Object Data Source ,Linq and sql or other any way


my query is



my data is

HR    HR    Rec    Records    Leave    Leave Records    HRL.0001    Policy and Process for leave record.    27.06.2010    30.06.2010    WIP    Edlink
HR    HR    Rec    Records    Leave    Leave Records    HRL.0002    Quarterly Review    01.07.2010    04.07.2010    Planned    Edlink
HR    HR    DB    Database    SAL    Salary    DDS.0001    Calculation of Monthly salary    08.08.2010    09.08.2010    WIP    Edlink
HR    HR    Rec    Records    Ind    Induction Records    HRI.0001    Completion of dossiers.    08.07.2010    10.07.2010  

What am I doing wrong in this LINQ query


I am retrieving an INT value from the one column in my "Counters" table.  I want to cast it to an int then increment it.  The error thrown states that sHitCounter (note that this is not names as it appears but rather the 's' is for "string) is uninitialized at the "parse..." line.

#region Counters
    public class Counters
        public int hCounter { get; set; }
        public static int HitCounter()
            string sHitcounter;
            int iHitcounter;
            IVA.Classes.DataClasses1DataContext hc = new IVA.Classes.DataClasses1DataContext();
                var hitC = 
                    from Counter in hc.GetTable<IVA.Classes.HitCounter>()
                    select Counter;

                foreach (var Counter in hitC)
                    sHitcounter = Counter.ToString();

                iHitcounter = Int32.Parse(sHitcounter);
                    return (iHitcounter);

    }//Class Counters


Annoying SQL exception, probably due to some OO/linq code done wrong


I started working on this "already started" project, and I'm having a really annoying error when trying to execute some interactions with SQL Server 2008:

The server failed to resume the transaction

One of these errors I get in this specific method call:

The aspx.cs Call:


busProcesso openProcess = new busProcesso(pProcessoId);
        if (openProcess.GetDocument() == null)
            //Irrelevant code.
    catch{ //... }

The Business class (relevant part):
public class busProcesso : IbusProcesso
        public Processo vProcesso { get; set; }

        RENDBDataContext db;

        public busProcesso()
            vProcesso = new Processo();

        public busProcesso(decimal pProcessoId)
            db = new RENDBDataContext();
                 vProcesso = db.Processos.SingleOrDefault(x => x.Id == pProcessoId);
            catch (Exception ex)
                throw new Exception(ex.Message, ex);

        public string GetDocument()

showing Wrong Data while loading excel sheet, need help urgent



I am trying to load data from an excel sheet to a table in sql server. in the excel-source when i press preview button data for one column in the excel sheet is coming as null. the column has numbers and the format of the cell is 'general'..? what could be wrong and how could i resolve.? need help urgently..?

Playing with Linq grouping: GroupByMany?

One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

LINQ : Implementing IN and NOT IN

I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

Linq to Sql CompiledQuery container

Ok now let's go. Here is just a little trick but with some interesting patterns that could be useful in some other contexts not connected to Linq to Sql.

When using Linq expressions, like with Linq to Sql, translating the expression into something else (sql for example) is taking time and resources. Sometimes it's negligible, sometimes not...

LINQ to SQL Paging using GridView in C# and ASP.NET 3.5

This tutorial will show you how we can extend the LINQ to SQL Class and create methods that will allow us to page data from a SQL database. C# version.

What is Lambda Expressions In LINQ

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

How to create 3 tier application using LINQ

As you know that in 3 tier architecture there are three layers

User interface layer. (Is our Form in Windows application and .aspx page in Web application)
Data Access layer. (Which provides interface between Business logic layer and Database)
Business Logic layer.(Which stores your application logic)

Building a LINQ Provider

Throughout this article, we will build a simple IQueryable provider similar to the LINQ to SQL provider demonstrating what is needed to build a custom provider that is capable of executing LINQ queries and performing create, update and delete operations.

LINQ to SQL Performance Considerations

As developers we have a wide array of tools at our disposal. One of the most time consuming, but most beneficial tasks we must undertake is to determine which of those tools to use for a given situation.

Passing Linq Statement between master and content page


I usually work with windows forms, and am just starting to work with ASP.Net, so appologies if this is a dumb question!

I have a master page which has a search button on it. The results of this are built up using a Linq statement and if there are any results, I want to display the results in a contents page.

On the masterpage, I have the following code:

Private _res

    Public Overridable ReadOnly Property SearchRes()
            Return _res
        End Get
    End Property

 Private Sub DoSearch()
   'some code to get a linq result

    If res.Any Then
            _res = res
            Server.Transfer("SearchResults.aspx", True)
            'no results
            LabelNoRes.Visible = True
        End If
 End Sub

On the SearchResults.aspx page I have this code.

Dim m As pxSite = CType(Page.Master, MasterPage)
        If m.SearchRes IsNot Nothing Then
            Label1.Text = "Results found = " & m.SearchRes.Count
        End If

m.searchRes is always nothing. 

What am I doing wrong here?


Linq - add data to database then email user the details


Hi all

I'm not sure how to structure the code for this but what I want to do is be able to add data to a database, and once this has completed successfully, then email the user to say the details have been added successfully to the database.

I need to:

1. Check that the relevant data has been added into the database then

2. Email the details of the relevant data when completed. 


Thanks in advance for your help,




Wrong Account being used to access files - Help - No Impersonation


I run a simple .aspx website on a Windows Server 2008 machine.

There is NO impersonation, and System.Security.Principal.WindowsIdentity.GetCurrent().Name returns NT AUTHORITY\NETWORK SERVICE, which it the account which the application pool runs. In my web.config, I have <authentication mode="Forms">.


I tried to test the security of the application and server by removing file permissions to the .aspx files. I was greatly worried when the website continued to run without problem (it should not have been able to read the .aspx files).

By turning on file level auditing, I discovered that the .aspx files were being read by the machine$ account (if the machine is called Serv1, then the files would be read by the Serv1$ account, which seems to have access to all files on the local machine).


Is this a security breach or is this behaviour by design ?

Please can somebody assist, as I am worried.

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