Solved

Convert VB.NET LINQ code to C#

Posted on 2008-06-10
9
586 Views
Last Modified: 2013-12-17
Convert VB.NET LINQ code to C#
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 

        Dim revisioni = From revisione As Word.Revision In Me.Revisions _

                        Where revisione.Author = "MeBoys" _

                        Order By revisione.Date Descending _

                        Select revisione.Range.Text
 

        Dim risultato As String = String.Empty
 

        For Each rev In revisioni

            risultato += String.Concat(rev, Environment.NewLine)

        Next
 

        MessageBox.Show(risultato)

    End Sub

Open in new window

0
Comment
Question by:Vivek Thangaswamy
  • 4
  • 3
  • 2
9 Comments
 
LVL 21

Assisted Solution

by:naspinski
naspinski earned 225 total points
ID: 21754038
This should do it, I just didn't know what class to include in the foreach.  It will be one that your dbml produced:
var revisioni = from revisione in Me.Revisions where revisione.Author.Equals("MeBoys") orderby revisione.Date descending select revisione.Range;
 

string risultato  = string.Empty;
 

foreach(REVISION rev in revisioni)//I am not sure what class you are using here, you will have to change REVISION on this one

    risultato += String.Concat(rev, Environment.NewLine);
 

MessageBox.Show(risultato);

Open in new window

0
 
LVL 11

Author Comment

by:Vivek Thangaswamy
ID: 21760427
'Me' does not exist in the current context compilation error
and when i change it 'this'

Error      1      Could not find an implementation of the query pattern for source type 'Microsoft.Office.Interop.Word.Revisions'.  'Where' not found.  Consider explicitly specifying the type of the range variable 'revisione'.      ""      42      47      
0
 
LVL 21

Expert Comment

by:naspinski
ID: 21760605
sorry, forgot to change me to this.

Where is incorrect, it is 'where' in c# - case-sensitive
0
 
LVL 11

Author Comment

by:Vivek Thangaswamy
ID: 21760779
'where'  its in correctly return as starting with small letter w
even i'm getting the same error

for more this is wht i'm tring to convert
http://www.vbdotnetheaven.com/UploadFile/progalex/LINQWord2007VSTO03082008194003PM/LINQWord2007VSTO.aspx
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 21

Expert Comment

by:naspinski
ID: 21760901
i have never seen anyone use 'this' as a reference so I am not following 100% I dont think.  Do you have a DBML?  or how are you connecting to your data?
0
 
LVL 11

Author Comment

by:Vivek Thangaswamy
ID: 21761286
No.. this will read the Word File properties and read the properties....
0
 
LVL 21

Expert Comment

by:naspinski
ID: 21761449
I am sorry, I have never used word interop with linq before.
0
 

Accepted Solution

by:
used2could earned 275 total points
ID: 21781522
Does this work?
        private void Button1_Click(object sender, EventArgs e)

        {

            var revisioni = (from revisione in this.Revisions

                             where revisione.Author == "MeBoys"

                             orderby revisione.Date descending

                             select revisione.Range.Text

                                 );

            StringBuilder risultato = new StringBuilder();

            foreach (var rev in revisioni)

            {

                risultato.Append(string.Concat(rev,Environment.NewLine));

            }
 

            System.Windows.Forms.MessageBox.Show(risultato.ToString());

        }

Open in new window

0
 

Expert Comment

by:used2could
ID: 21781557
Sorry Master, i ended up posting pretty much what you posted.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Close word object 13 38
Code works but I need to redo it and assign values to Model 7 33
Problem with Filesystemobject or .NET version 3 35
Tool Box 2 35
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now