Search This Blog

Friday, October 24, 2014

Telerik Reporting Binding C# Example

Telerik > Reporting > ObjectDataSource

ObjectDataSource component represents the middle-tier object and provides data retrieval capabilities. 
Example


var ods = new Telerik.Reporting.ObjectDataSource();
ods.DataSource = GetData();
ods.DataMember = "Products"; //table to bind to        
Telerik.Reporting.Report report = new Telerik.Reporting.Report();
report.DataSource = ods;
Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
reportSource.ReportDocument = report;
reportViewer1.ReportSource = reportSource;
reportViewer1.RefreshReport();





Thursday, October 23, 2014

Get Computer Name C#

C#  > System > Environment ClassMachineName

Returns the computer's name. This is established at system start up when the name is read from the registry. 

Example



   string _name = Environment.MachineName;





ADO.NET LINQ to SQL

ADO.NET LINQ to SQL

Is a component for managing relational data as objects. 

  • the data model of a relational database is mapped to an object model  
  • translates into SQL the language-integrated queries in the object model and sends them to the database for execution
  • translates database result  back to objects 
Methods





Tuesday, October 21, 2014

VB.NET LINQ TO SQL Delete Rows From Database

ADO.NET > LINQ TO SQL > Delete rows from database

DeleteOnSubmit removes entity, but does not disappear from the query results until after SubmitChanges is called. 

Example


C#

var deleteData =
    from details in db.GetDetails
    where details.ID == 1
    select details;

foreach (var detail in deleteData )
{
    db.Details.DeleteOnSubmit(detail);
}

try
{
    db.SubmitChanges();
}
catch (Exception e)
{
}



VB.Net

Dim deleteData = _
    From details In db.GetDetails() _
    Where details.ID = 1 _
    Select details

For Each detail As Detail In deleteData
    db.Details.DeleteOnSubmit(detail)
Next 

Try
    db.SubmitChanges()
Catch ex As Exception

End Try





Friday, October 17, 2014

Check Deny Access File C#

C# > System.Security > AccessControlAuthorizationRuleCollection 

AuthorizationRuleCollection 

Represents a collection of AuthorizationRule objects.

Example


Check Deny Access File C#

public bool CheckDenyAccessFile(string filePath)
{
       FileSecurity fs = File.GetAccessControl(filePath);
       AuthorizationRuleCollection acl = fs.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));
       bool deny = false;
       for (int x = 0; x < acl.Count; x++)
       {
              FileSystemAccessRule currentRule = (FileSystemAccessRule)acl[x];
              AccessControlType accessType = currentRule.AccessControlType;
              if (accessType == AccessControlType.Deny && (currentRule.FileSystemRights & FileSystemRights.ListDirectory) == FileSystemRights.ListDirectory)
                {
                    deny = true;
                    break;
                }
        }
        return deny;
}





Writes lines to text file C#

C# > IO  > FileInfo > CreateText

Writes text a new text file.

Example


Writes lines to text file C#


string path = Path.GetTempFileName();
FileInfo fi = new FileInfo(path);

using (StreamWriter sw = fi.CreateText())
{
      sw.WriteLine("Line1");
      sw.WriteLine("Line2");
      sw.WriteLine("Line3");
      sw.WriteLine("Line4");


}      





FileInfo Class C#

C# > IO  > FileInfo Class

FileInfo

Use this class for working with files: create, open, delete, 

move, rename.

Methods

Properties