Monday, December 13, 2010
Three-Tier Architecture Vs MVC
Separating Out the Domain Model
Wednesday, December 1, 2010
Can you find System.Web in add reference ? [.NET 4.0]
After goggling I found that I need to add a .NET reference to "System.Web.dll" because I am making a Windows Application.
But unfortunately I could not find where is the "System.Web.dll" ? Its not available in the .NET references . :(
Finally figure out why is that! Yeah its because, I have targeted the Windows application to .NET framework4.0
But that's no an excuse I know;
Meanwhile I did further investigation of why it was not showing in the add reference tab of 4.0 project.
Yeah I got the issue, this is because, by default the project created in Framework 4.0 is defaulted to the profile.
Open the project properties and you can see it as shown below.
Once you have done this, you can go and add the reference to System.Web
Hope this helps!!!
Tuesday, November 30, 2010
What’s New in ASP.NET MVC 2
ASP.NET Web Forms Vs ASP.NET MVC
Saturday, November 27, 2010
Who Should Use ASP.NET MVC?
What’s Wrong with ASP.NET Web Forms?
• ViewState weight:
The actual mechanism of maintaining state across requests(ViewState) often results in giant blocks of data being transferred between client and server. It can reach hundreds of kilobytes in many real-world applications, and it goes back and forth with every request, frustrating site visitors with a long wait each time they click a button or try to move to the next page on a grid.
ASP.NET AJAX suffers this just as badly,1 even though bandwidth-heavy page updating is one of the main problems that Ajax is supposed to solve.
(e.g., manipulating the server-side control tree) with their application logic (e.g., manipulating database data) in these same monstrous code-behind classes. Without better separation of concerns, the end result is often fragile and unintelligible.
• Limited control over HTML:
• Leaky abstraction:
example, rich client-side interactivity is made excessively difficult because all client-side state can be blown away at any moment by a postback.
• Difficulty applying automated tests:
Thursday, November 25, 2010
How to download ".ZIP" file from FTP server and unzip it into a local folder!
please go through the code sample and comment lines, if you have any further suggestion and explanations please send me [usgamage@gmail.com]
NOTE: Here I am using a third party ".dll" file named "ICSharpCode.SharpZipLib.Zip.dll" to unzip the folder.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;
using ICSharpCode.SharpZipLib.Zip;
using System.Collections;
namespace XMLFileDownloader
{
public class XMLFileDownloader
{
//Variable declarations for FTP login credentials to the FTP ServerURI
string ftpUSER = string.Empty;
string ftpPassword = string.Empty;
string ftpServerURI = string.Empty;
string LocDirPath = string.Empty;
string ZIPFileName = string.Empty;
bool deleteZipFile = false;
int Count = 0;
///
/// Method to get Configuration values from SSIS config File
///
///
///
public int ReadConfigData(string ConfigFile)
{
XmlDocument xmldoc = null;
try
{
xmldoc = new XmlDocument();
xmldoc.Load(ConfigFile);
XmlNodeList nodeList = xmldoc.DocumentElement.ChildNodes;
foreach (XmlElement element in nodeList)
{
if (element.Name == "Configuration")
{
switch (element.Attributes["Path"].InnerText)
{
case "ftpUSER": ftpUSER = element.ChildNodes[0].InnerText.ToString().Trim().Length != 0 ? element.ChildNodes[0].InnerText.ToString() : "";
break;
case "ftpPassword": ftpPassword = element.ChildNodes[0].InnerText.ToString().Trim().Length != 0 ? element.ChildNodes[0].InnerText.ToString() : "";
break;
case "ftpServerURI": ftpServerURI = element.ChildNodes[0].InnerText.ToString().Trim().Length != 0 ? element.ChildNodes[0].InnerText.ToString() : "";
break;
case "LocDirPath": LocDirPath = element.ChildNodes[0].InnerText.ToString().Trim().Length != 0 ? element.ChildNodes[0].InnerText.ToString() : "";
break;
case "ZIPFileName": ZIPFileName = element.ChildNodes[0].InnerText.ToString().Trim().Length != 0 ? element.ChildNodes[0].InnerText.ToString() : "";
break;
case "DeleteZIPFile": deleteZipFile = Convert.ToBoolean(element.ChildNodes[0].InnerText.ToString().Trim());
break;
}
}
}
}
catch (Exception Exception)
{
Console.WriteLine("Configuration file invalid" + Exception.Message);
}
return GetFileList();
}
///
/// Initiate config values
///
public int IniConfig(string ftpUser, string ftpPwd, string uri, string locFilelocation, bool deletefile)
{
ftpUSER = ftpUser;
ftpPassword = ftpPwd;
ftpServerURI = uri;
LocDirPath = locFilelocation;
deleteZipFile = deletefile;
int _totDownload = GetFileList();
if (_totDownload > 0)
{
ZipFiles();
}
return _totDownload;
}
///
/// Methos to Get Download .xml and .csv files into
/// the local directory
///
///
public int GetFileList()
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
WebResponse response = null;
StreamReader reader = null;
try
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerURI));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUSER, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.Proxy = null;
reqFTP.KeepAlive = false;
reqFTP.UsePassive = true;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
if (result.ToString() != null)
{
result.Remove(result.ToString().LastIndexOf('\n'), 1);
downloadFiles = result.ToString().Split('\n');
foreach (string file in downloadFiles)
{
if (Path.GetExtension(file) == ".zip")
{
if (Download(file))
{
Count = Count + 1;
Console.WriteLine("Tot. Zip file Downloaded: " + Count);
}
}
}
}
}
catch (Exception ex)
{
if (reader != null)
{
reader.Close();
}
if (response != null)
{
response.Close();
}
Console.WriteLine(ex.Message);
;
}
finally
{
downloadFiles = null;
}
return Count;
}
///
/// This method list all ".zip" files and pass each filename fileunzip method
///
///
public void ZipFiles()
{
int totFiles = 0;
try
{
ArrayList _zipFileList = GenerateFileList(LocDirPath); // generate file list
if (_zipFileList.Count > 0)
{
foreach (string singleFile in _zipFileList)
{
UnZipFiles(singleFile);
totFiles = totFiles + 1;
Console.WriteLine("Total Files extracted: " + totFiles);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error in listing all '.ZIP' files into string array" + ex.Message);
}
}
///
/// This method list all .zip files in given directory
///
///
///
public static ArrayList GenerateFileList(string Dir)
{
ArrayList fils = new ArrayList();
bool Empty = true;
foreach (string file in Directory.GetFiles(Dir)) // add each file in directory
{
if (file.Contains(".zip"))
{
fils.Add(file);
Empty = false;
}
}
if (Empty)
{
if (Directory.GetDirectories(Dir).Length == 0)
// if directory is completely empty, add it
{
fils.Add(Dir + @"/");
}
}
return fils; // return file list
}
///
/// This method will extract the given .zip file into the local dir.
///
public void UnZipFiles(string zipPathAndFile)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile));
ZipEntry theEntry;
string tmpEntry = String.Empty;
while ((theEntry = s.GetNextEntry()) != null)
{
string fileName = Path.GetFileName(theEntry.Name);
if (fileName != String.Empty)
{
if (theEntry.Name.IndexOf(".ini") < 0)
{
string[] _str = theEntry.Name.Split('/');
string _currentFile = _str[_str.Length - 1].ToString();
string fullPath = LocDirPath + "\\" + _currentFile;
fullPath = fullPath.Replace("\\ ", "\\");
string fullDirPath = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
FileStream streamWriter = File.Create(fullPath);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
}
s.Close();
if (deleteZipFile)
File.Delete(zipPathAndFile);
}
///
/// Method to download individual file
///
///
public bool Download(string file)
{
bool isDownloaded = false;
try
{
string uri = ftpServerURI + "/" + file;
Uri serverUri = new Uri(uri);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return isDownloaded;
}
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerURI + "/" + file));
reqFTP.Credentials = new NetworkCredential(ftpUSER, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = true;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream = response.GetResponseStream();
FileStream writeStream = new FileStream(LocDirPath + "\\" + file, FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
}
writeStream.Close();
response.Close();
isDownloaded = true;
}
catch (WebException e)
{
Console.WriteLine(e.Message, "Download Error");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message, "Download Error");
}
return isDownloaded;
}
}
}
Monday, October 25, 2010
Check Record Exists in SQL Server Database [C#.NET] via Checksum field
Wednesday, September 22, 2010
Share Point 2010: Create a custom site definition Template (Topic Site Template)
Getting Started:
Start by running Visual Studio 2010 (I’ll call it “VS-2010” from now on) and select New Project from start screen. (Figure: VS Welcome Screen)
Figure: VS Welcome Screen
Create new “Topic Site - Level” template project (Custom Site Template).
To create custom site template, we need to create a new “Site Definition” project using Visual Studio 2010.
You can create custom site template using Visual Basic or Visual C#. For now, Select Visual C# on the left, then pick "Site Definition" project under the category named “Sharepoint” then “2010”. Name your new project "TopicSiteLevelDemo" and click OK. (Figure: Create New Site Definition project)
Figure: Create New Site Definition project
“Sharepoint Customization Wizard” window opens, specify the site URL and security level for debugging
(Ex: http://usg:1909/). Click on “Validate” button for site URL validation and then “Finish”. (Figure: SharePoint Customization Wizard)
On the right-hand side is the Solution Explorer showing all the files and folders in your application. The big window in the middle is where you edit your code and spend most of your time. Visual Studio used a default template for the Site Definition project you just created, so you have a working application right now without doing anything! This is a simple " TopicSiteLevelDemo!” project, and it is a good place to start for our application. (Figure: Default template for the Site Definition File)
Out of the box this default template gives you three files; “Onet.xml”, “webtemp.xml” and “default.aspx” files.
Let me explain each files in brief which relevant to the “Topic Site Level - 1” template.
Onet.xml File
In an Onet.xml file, the Feature element is used within a site definition configuration to contain a reference to a Feature instance and default property values. The Configuration element specifies lists and modules to use when creating SharePoint sites. For information about the format and elements used in site definitions.
SharePoint Foundation activates Features specified within the Onet.xml file in the order that they are listed. Consequently, you must specify Features that are depended upon before Features that depend upon them.
The default “onet.xml” file uses the default “V4.master” file, for the site definition’s master page.
For “Infor Sales Portal Topic site levels”, used custom master page named, “infor_V4.master”.
This defined it “onet.xml” file under the tags named, “
Configurations Element
Each configuration element in the configurations section specifies the lists, modules, and Features that are created by default when the site definition configuration or Web template is instantiated.
ListTemplates Element
The ListTemplate section specifies the list definitions that are part of the “Topic Site” template. Each ListTemplate element specifies an internal name that identifies the list definition and also specifies the display name for the list definition. Example: “Topic Site Announcements”
Each List element specifies the title of the list definition and the URL for where to create the list. (Figure: ListTemplate element of “TopicS ite – Level 1” onet.xml)
SiteFeatures Element
The “SiteFeature” element contains references to site to site collection and site – scoped features to include in the site definition.
WebFeatures Element
The “WebFeature” element contains references to site to site collection and site – scoped features to include in the site definition.
Modules Element
The Modules collection specifies a pool of modules. Any module in the pool can be referenced by a configuration if the module should be included in Web sites that are created from the configuration. Each Module element in turn specifies one or more files to include, often for Web Parts, which are cached in memory on the front-end Web server along with the schema files. You can use the Url attribute of the Module element to provision a folder as part of the site definition. This markup is supported only for backward compatibility. New modules should be incorporated into Features. (Figure: Module element of “TopicSite – Level 1” onet.xml)
Figure: Module element of “TopicSite – Level 1” onet.xml
Getting SharePoint in-buit list web part references in onto the “InforSalesPortal” Home Page; (Figure:
Figure:
Web* Temp.xml File
Example: “webtemp_TopicSiteLevel1.xml”
Each server in a deployment of Microsoft SharePoint Foundation has at least the originally installed WebTemp.xml file located in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LCID\XML folder, where LCID is the numeric ID of the language/culture, such as 1033 for English. There may also be one or more custom WebTemp*.xml files. The WebTemp*.xml files contain an itemization of the site definition configurations that are available in the UI for users to select when creating a new Web site. The UI varies depending on whether the Silverlight or HTML site creation page is being used.
The Template element specifies the site definitions that are being made available in the WebTemp*.xml file. Each site definition is defined with a Template element. Each site definition has one or more site definition configurations that can be used to instantiate sites. Each Template element specifies a unique ID and a name that corresponds to a site definition subfolder within the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates folder. (Example: “%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates\TopicSiteLevel1”)
A Template element can contain any number of Configuration child elements. Each such child represents a site definition configuration.
The ID attribute of each Configuration element corresponds to the ID of another Configuration element that is in an Onet.xml file. The second Configuration element specifies the lists and modules of the site definition configuration.
Each Configuration element in a WebTemp*.xml file also specifies the title and description (and the path to the image) of the configuration that is displayed in the SharePoint Foundation UI when a user is creating a new site. A configuration can be hidden from the user interface (UI) by setting its Hidden attribute to TRUE.
The DisplayCategory attribute of a Configuration element in a WebTemp*.xml specifies the category of site type that the site appears under in the UI; for example, "Infor" (Figure: “webtemp_TopicSiteLevel1.xml” file of “Topic Site – Level 1” template)
Figure: “webtemp_TopicSiteLevel1.xml” file of “Topic Site – Level 1” template
default.aspx file
This is the Topic Site template home or content area and layout of the Site Definition.(Figure: default.aspx file)
Figure: default.aspx file