Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Dynamically changing META Tags in MasterPages from ContentPage

In addition to one of my previous article reference regarding Changing Page Title and Meta Tags with Master Pages.

The earlier method doesn't work in some cases so I was looking for some proper method.
And finally I have found another method of changing meta tag values.

You can visit the following website that describes the content with proper example.

The file 'Default.aspx.cs' does not exist.


In an ASP.NET project, when you compile your project it shows message "Rebuild Succeeded".

As soon as you run your project you may encounter and error message that says
The file 'Default.aspx.cs' does not exist.
How is it possible, your compilation was successfull and a .cs file is missing :)
Below is the solution that you can look into:

How to run a batch file from C# in desktop application

To execute the batch file in c#, here is the code through which you can easily get the output from batch file.


// Get the full file path
string strFilePath = filePath;(full path for ex: c:\\batchfile\\somefile.bat)

// Create the ProcessInfo object

C# Programming and Microsoft Visual Studio Tips and Tricks

Abstracts:


Introduction
C# is a great language. It is relatively easy to learn with its simpler syntax over C++ programming and Java. Ten years down the line it still is a strong competitor. It has had improvement year after year, with new features added with its every release. It has not disappointed the C# developer community.

1. Environment.Newline

Did you know that this property is platform independent and allows you to output the new line characters as per the platform?

Console.WriteLine("My Tips On ,{0}C#", Environment.NewLine);

2. Namespace Alias

Did you know that you can substitute your big namespaces with shorter aliases? Or have you faced a situation where you had to qualify the object with its complete namespace to avoid ambiguity.

Look at the sample below where there is a generic library created with extended .NET Framework controls.

using System.Web.UI.WebControls;
using MyGenericLibrary.UserControls;

/* Assuming that you had a Text Box control in both the namespace, you would have to fully qualify the class object with the complete namespace. To avoid that, you can use namespace alias. Change as below */



Get month name by month number - C#

One of the simplest method to get month name from month number that i have implemented just today :) (after a loooong time)


System.Globalization.DateTimeFormatInfo strDateTimeFormatInfoObj = new System.Globalization.DateTimeFormatInfo();
string strMonthName =
strDateTimeFormatInfoObj.GetMonthName(9).ToString();

How to : Use Visual Studio TODO Comments

There are many type of comments available in Visual Studio, but have you ever seen the TODO comment?

abstract:

You have many tasks to remember, and you want to track them in Visual
Studio with TODO comments. These comments can help get you more
organized about your projects. You want to get the interface set up and
gain a way to list your to-do items in a central place. Here we look at
ways you can use TODO comments in your C# programs.

Using TODO

TODO
comments allow you to tell Visual Studio to maintain a central list of
tasks, which it reads from many different places in your code. The Task
List is a panel or floating window in Visual Studio that will display
all the TODO comments in your project. To open the list, go to View menu
-> Task List.


Some example TODO comments

You probably have a lot of code
that needs a lot of work. If you don't, then you need to write code that
needs a lot of work. Here are some examples of TODO lines that
Visual Studio 2008 will notice and put into its special Task Pane.

<i>//todo: fix dialog windows
//TODO: work on SQLCE guide
// Todo new screenshot</i>

Description of example. This
will appear in your tasks pane as a separate task. Note that you have
some flexibility with these tokens. The strings "todo", "TODO", and
"TODO" all work equally well—Visual Studio's parser gives you a little
bit of freedom.

More comments

Here we make a more general
point about comments in the C# programming language. Comments are used
only at the source level of your program, not the compiled version of
the program. The TODO comments noted here are parsed by Visual Studio in
the IDE. You can find more about how comments relate to C# programs
here.


Click here to read  the original article on TODO Comment



Move record between selected listbox in c#.net using javascript

One day i am suffering in internet, and got the important link to swap the record Up/Down/Right/Left between ListBox. This link may save your lot of work:

http://www.mattkruse.com/javascript/selectbox/index.html



By

Getting a list of files from a MOSS document library using a SharePoint web service

A useful link that shows how to get list of files form doc lib of MOSS using webservice


Excerpts:

My challenge was simple. I needed to develop an SSIS package that
would download and extract data from
Publish Post
every Excel file held in document
libraries across several SharePoint sites. SSIS was the natural choice as
the data needed to be cleaned and validated before being imported into a
database. However, SSIS is not great with web services – especially in the data
flow. As I not worked with the SharePoint web services much, I started with a
good old Console application.
MOSS, or more accurately, WSS provides a whole host of web services to obtain information about
SharePoint sites. However, figuring out which method to invoke and what
parameters to pass is more problematic. Especially as many of the
parameters are chunks of Collaborative Application Mark-up Language (CAML) – a
dialect of XML developed by Microsoft specifically for use with SharePoint.
A False Start
My first console app simply obtained the GUID of the document library using the
GetListCollection() method of the Lists web service. The GUID was then
passed to the GetListItems() method which duly provided all documents and folders
at the top level of the document library. It then seemed logical to me to
recursively call the GetListItems() method using the GUID of each sub-folder.
On no, how wrong could I be! The GetListItems() method simply chokes on these
folder GUIDs.

On searching the internet I found many other incorrect forum posts and blog
entries about the same topic – but no working solutions. I also made an
extensive search of my eBook collection – but again no solutions – which
overall motivated me to write this blog entry.

The solution - RTFM
Well, if I had read the whole page in the manual, I would have got to the
solution earlierCrying. The key to my puzzle was
the QueryOptions XML fragment which
has both a Folder element and the all important <ViewAttributes
Scope="Recursive" /> element. Using these elements together, it is
possible to obtain a list of all documents in all subfolders in the list.
Indeed, it does not even bother returning the subfolder details!

So here is the code for my working C# sample.


using System;



using System.Collections.Generic;



using System.Text;



using System.Xml;



using System.Web.Services;



using System.Web;



using System.Net;





namespace ConsoleApplication1



{
class Program
{

static void Main(string[] args)
{



string siteUrl = @"http://yourserver/sites/yoursite";

string documentLibraryName = @"Shared
Documents"
;

SharePointList.Lists
wsList = new SharePointList.Lists();

wsList.Credentials
= System.Net.CredentialCache.DefaultCredentials;

WebProxy
proxyObj = new WebProxy("yourproxy", 80);

wsList.Proxy
= proxyObj;

wsList.Url
= siteUrl + @"/_vti_bin/lists.asmx";

// get a list of all top level lists

XmlNode
allLists = wsList.GetListCollection();

// load into an XML document so we can use XPath to query
content

XmlDocument
allListsDoc = new XmlDocument();

allListsDoc.LoadXml(allLists.OuterXml);

// allListsDoc.Save(@"c:\allListsDoc.xml"); // for debug

XmlNamespaceManager
ns = new
XmlNamespaceManager(allListsDoc.NameTable);

ns.AddNamespace("d", allLists.NamespaceURI);

// now get the GUID of the document library we are looking
for

XmlNode
dlNode = allListsDoc.SelectSingleNode("/d:Lists/d:List[@Title='"
+ documentLibraryName + "']", ns);

if (dlNode == null)

{

Console.WriteLine("Document
Library '{0}' not found!"
, documentLibraryName);

}

else

{

// obtain the GUID for the document library and the webID

string documentLibraryGUID = dlNode.Attributes["ID"].Value;

string webId = dlNode.Attributes["WebId"].Value;

Console.WriteLine("Opening
folder '{0}' GUID={1}"
, documentLibraryName, documentLibraryGUID);

// create ViewFields CAML

XmlDocument
viewFieldsDoc = new XmlDocument();

XmlNode
ViewFields = AddXmlElement(viewFieldsDoc, "ViewFields",
"");

AddFieldRef(ViewFields,
"GUID");

AddFieldRef(ViewFields,
"ContentType");

AddFieldRef(ViewFields,
"BaseName");

AddFieldRef(ViewFields,
"Modified");

AddFieldRef(ViewFields,
"EncodedAbsUrl");

//viewFieldsDoc.Save(@"c:\viewFields.xml"); // for debug

// create QueryOptions CAML

XmlDocument
queryOptionsDoc = new XmlDocument();



...
...
...
...


Click here to read full article.


Is the above link useful to you? Let us know your feedback, it will help us to improve our posting(s). or You can send your feedback linkOblast.

BUG: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

I'm using the Enterprise edition of VS 2005. When I debug my project an exception is raised - 'Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack'. I can't find anything about this on-line.

The Code look like:

try

{

some logic

Response.Redirect("LoadedAcmdata.aspx?Temp="+Request.QueryString["Temp"].ToString());

}


catch (Exception ex)
{
throw ex ;
}

I sware there is no bug in this code, when tried to execute this code it creates an exception

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

This bug screwed my head. but finally i found solution.

Cause of problem: The Response.End method ends the page execution and shifts the execution to theApplication_EndRequest event in the application's event pipeline. The line of code that followsResponse.End is not executed.This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.

Solution:

  • For Response.End, call theHttpContext.Current.ApplicationInstance.CompleteRequest method instead ofResponse.End to bypass the code execution to the Application_EndRequest event.
  • For Response.Redirect, use an overload, Response.Redirect(String url, bool endResponse) that passes false for the endResponse parameter to suppress the internal call to Response.End. For example:

Response.Redirect("nextpage.aspx",false);

If you use this workaround, the code that follows Response.Redirect is executed.

  • For Server.Transfer, use the Server.Execute method instead.

This solution really helps me.



Is the above link useful to you? Let us know your feedback, it will help us to improve our posting(s). or You can send your feedback linkOblast.

FOREACH Vs. FOR (C#)


Excerpts:

In my experience, there are two kinds of
programmers. Those who write something to get the work done and those
who want to write good code. But, here we get a big question. What is
good code? Good code comes from good programming practices. What are
good programming practices? Actually, my aim here is not to talk about
good programming practices (I’m planning to write something related to
that in future!), rather to talk more about writing something which
will be more effective. I'm only going to look more deeper of two loops
which are commonly used nowadays


For full article click here

or

Visit http://www.codeproject.com/KB/cs/foreach.aspx


All thanks to Mr. Saujanya Gupta for providing such a good link.

---------------------------
Do you like the above link? Let us know your opinion.

Microsoft StyleCop

StyleCop
analyzes C# source code to enforce a set of style and consistency
rules. It can be run from inside of Visual Studio or integrated into an
MSBuild project.

For more information about Microsoft StyleCop click here

or

visit http://code.msdn.microsoft.com/sourceanalysis


Do you have any comment?

C# Tutorials

A good site that provides tutorials in C# that includes

  • Expressions, Types, and Variables
  • Control Statements - Selection
  • Control Statements - Loops
  • Methods
  • Namespaces
  • Introduction to Classes
  • Class Inheritance
  • Polymorphism
  • Properties
  • Indexers
  • Structs
  • Interfaces
  • Introduction to Delegates and Events
  • Introduction to Exception Handling
  • Using Attributes
  • Enums
  • Overloading Operators
  • Encapsulation
  • Introduction to Generic Collections
  • Anonymous Methods
  • Topics on C# Type
Click here to visit site.

Is the above link useful to you? Let us know your feedback, it will help us to improve our posting(s). or You can send your feedback linkOblast.

C# Samples for Visual Studio 2008

Hello Guys,

Here is the link to download sample C# code for Visual Studio 2008.

http://code.msdn.microsoft.com/csharpsamples

It will be best collection bcz its provided by msdn itself.

Check it out :)

Is the above link useful to you? Let us know your feedback, it will help us to improve our posting(s). or You can send your feedback linkOblast.