Aug 30, 2015
Access Internal class or member on another Assemblies in C#
Kalpesh Satasiya
3:26 PM
asp.net, C#, Friend Assemblies, Internal class, Unit Test cases
No comments
I just happen same situation in my one of the project. So I have googling and spend some time on it and finding solution.
Writing this blog for them who having facing same situation. so that would be help for them.
C# having call Internal Assembly like in Visual Basic(VB) having call Friend Assembly.
Interal class InternalClass { public void Test() { Console.WriteLine("Sample Class"); } }If would like to access InternalClass on another assemblies then need to define each assemblies name on AssemblyInfo.cs with following line.
[assembly: InternalsVisibleTo("name of assembly here")]
i.e. If you want access InternalClass on assembly ABC then you will need to mention on AssemblyInfo.cs file for same.[assembly: InternalsVisibleTo("ABC")]
Hope that is help to you!!For more detail please click here
Aug 26, 2015
After Updating Windows 10 Sql Server Services Need to Start Manually
Kalpesh Satasiya
7:28 PM
sql server, Sql Server Services, Windows 10
No comments
So based on issue I had google it and find a solution. Which is about Sql Server Services.
So I need to start Sql Server Services manually after updating Windows 10.
Following are step to start Sql Server Services.
1. Press Window + R key so it will open Run window.
2. Now type "services.msc" and hit enter so it will open Service dialogue.
3. Now find sql server service from the Service list.
4. Once find it, just need to click on left panel of Start link.
5. Wait for few second and it will start it.
6. Now you can try to connect Sql Server Management studio to Sql Server.
Hope you got your solution.
Aug 12, 2015
Covnvert List to String in C#
Kalpesh Satasiya
5:56 PM
List, List to String, string
1 comment
So here we just quick look of string.Join code magic and get our expected result.
List
number.Add(1);
number.Add(4);
number.Add(50);
number.Add(78);
string strNumber = string.Join(",", number.ToArray());
Response.Write(strNumber);
Output: 1,4,50,78
Hope you enjoy it!!
Aug 8, 2015
Microsoft Window 10 Installed
So I was excited to upgrade because last 1-2 month we are waiting for Window 10 release and finally that dream come true.
Once I have clicked on OK button so that was started to upgrade and it was just taken few hours to upgraded.
First screen look after the Window 10 installation.
Jul 26, 2015
Fluent Validation for .NET
Kalpesh Satasiya
2:37 PM
.Net, FluentValidation, MVC, NopCommerce, WebApi
No comments
FuentValidation are recommended by many expert to use on existing and new website development stuff because its easy to used I mean its plug and play feature.
Personally I have experienced FuentValidation with NopCommerce, Web API, MVC and Asp.net applications.
How we get start with FluentValidation? Its very simple like other NuGet packages.
Install FluentValidation using Visual Studio Package Manger.
Install-Package FluentValidation
Please visit following link for more demo and document. so please go through demo and document so you will be get more idea how FluentValidation works.
https://github.com/JeremySkinner/FluentValidation
If you have any question about FluentValidation please write me. I will be very happy to write back to you.
How to add new table in NopCommerce
Kalpesh Satasiya
1:53 PM
Add new table, Controller, Entity Framwork, Model, MVC, NopCommerce, software developer, software development, View
2 comments
So I am going to starting with NopCommerce for how to add new table. This is the common question for newbie of NopCommerce.
Basically here sharing my experience with you guys that will help to other.
Step by step explanation for how to add new table on NopCommerce.
Going to explain based on the NopCommerce source code. So first open source code on visual studio then follow the below steps (Also refer any existing classes/table).
1. Create the Entity class related to table name (e.g. Enity.cs)
Path : Solution\Libraries\Nop.Core\Domain\Entity.cs
2. Create a Mapping class which bind class to Database table (e.g. EntityMap.cs)
Path : Solution\Libraries\Nop.Data\Mapping\EntityMap.cs
3. Create a Model class for MVC (i.e. for Admin or Web) (e.g EntityModel.cs)
Path : Solution\Presentation\Nop.Web\Models\EntityModel.cs (for Web)
Path : Solution\Presentation\Nop.Admin\Models\EntityModel.cs (for Admin)
4. Create a validator for model (e.g. EntityValidator.cs)
Path : Solution\Presentation\Nop.Web\Validators\EntityValidator.cs (for Web)
Path : Solution\Presentation\Nop.Admin\Validators\EntityValidator.cs (for Admin)
5. Create A Mapping Configuration On AutoMapperStartupTask.cs for Entity and Model
Path : Solution\Presentation\Nop.Admin\Infrastructure
Mapping Model to Entity and Entity to Model
Mapper.CreateMap<MyTest, MyTestModel>() .ForMember(dest => dest.Name, mo => mo.Ignore()) .ForMember(dest => dest.MyTestId, mo => mo.Ignore()); Mapper.CreateMap<MyTestModel, MyTest>() .ForMember(dest => dest.Name, mo => mo.Ignore()) .ForMember(dest => dest.MyTestId, mo => mo.Ignore());
6. Apply Mapping between Model and Entity on MappingExtensions.cs
Path : Solution\Presentation\Nop.Web\Extensions\(for Web)
Path : Solution\Presentation\Nop.Admin\Extensions\(for Admin)
7. Create a service class and service interface (e.g EntityService.cs , IEntityService.cs)
Path : Solution\Libraries\Nop.Services\IEntityService.cs
Path : Solution\Libraries\Nop.Services\EntityService.cs
8. Final step to create Controller and View for given Model.
Hope you get basic idea how to create/add new table on NopCommerce system.
Jul 19, 2013
Currency format with decimal point in asp.net
Kalpesh Satasiya
2:55 PM
ahmedabad, convert currency format, Currency decimal points, software developer, software development
No comments
{
string CurrencySymbols = "xof";
Response.Write(string.Format("{0:F" + getCurrencyDecimalPlaces(CurrencySymbols.ToUpper()) + "}", 12456.017312) + "
");
}
public static int getCurrencyDecimalPlaces(string CurrencySymbols)
{
Dictionary
#region Add Decimal
oCurrencyDictionary.Add("RUB", 2); //Russian Ruble
oCurrencyDictionary.Add("CHF", 2); //Swiss Franc
oCurrencyDictionary.Add("GBP", 2); //British Pound
oCurrencyDictionary.Add("EUR", 2); //Euro
oCurrencyDictionary.Add("USD", 2); //American Dollar
oCurrencyDictionary.Add("CAD", 2); //Canadian Dollar
oCurrencyDictionary.Add("INR", 2); //Indian Rupee
oCurrencyDictionary.Add("GHS", 2); //Ghana Cedi
oCurrencyDictionary.Add("NGN", 2); //Nigerian Naira
oCurrencyDictionary.Add("CNY", 2); //Chinese Yuan
oCurrencyDictionary.Add("BRL", 2); //Brazilian Real
oCurrencyDictionary.Add("HKD", 2); //Hong Kong Dollar
oCurrencyDictionary.Add("AED", 2); //UAE Dirham
oCurrencyDictionary.Add("JPY", 0); //Japanese Yen
oCurrencyDictionary.Add("XOF", 0); //CFA Franc (BCEAO)
oCurrencyDictionary.Add("XAF", 0); //CFA Franc (BEAC)
oCurrencyDictionary.Add("ARS", 2); //Argentine Peso
oCurrencyDictionary.Add("MXN", 2); //Mexican Peso
oCurrencyDictionary.Add("NPR", 2); //Nepalese Rupee
oCurrencyDictionary.Add("THB", 2); //Thai Baht
oCurrencyDictionary.Add("TRY", 2); //Turkish Lira
oCurrencyDictionary.Add("VEB", 2); //bolivar fuerte
oCurrencyDictionary.Add("VND", 2); //Vietnam Dong
oCurrencyDictionary.Add("UAH", 2); //Ukraine Hryvnia
oCurrencyDictionary.Add("SEK", 2); //Swedish Kronor
oCurrencyDictionary.Add("ZAR", 2); //South African Rand
oCurrencyDictionary.Add("PKR", 2); //Pakistani Rupee
oCurrencyDictionary.Add("PAB", 2); //Panama Balboa
oCurrencyDictionary.Add("NZD", 2); //New Zealand Dollar
oCurrencyDictionary.Add("MYR", 2); //Malaysian Ringgit
oCurrencyDictionary.Add("SGD", 2); //Singapore Dollar
oCurrencyDictionary.Add("BDT", 2); //Bangladeshi Taka
#endregion
if (oCurrencyDictionary.ContainsKey(CurrencySymbols))
{
return oCurrencyDictionary[CurrencySymbols];
}
else
{
return 2;
}
}
May 31, 2013
Convert enum to hashtable for dropdown list binding
Kalpesh Satasiya
11:40 AM
ahmedabad, Enum, Enum to HashTable, HashTable, software developer, software development, web designing, web developer, web development
2 comments
Mar 19, 2013
Nov 26, 2012
Aug 23, 2012
In Asp.net, how do I embed images in an email?
Kalpesh Satasiya
6:58 PM
ahmedabad, asp.net, Email with Embed Image, Embed Image, india, software developer, software development
4 comments
static void EmbedImages()
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("me@mycompany.com");
mail.To.Add("you@yourcompany.com");
//set the content
mail.Subject = "This is an email";
//first we create the Plain Text part
AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain");
//then we create the Html part
//to embed images, we need to use the prefix 'cid' in the img src value
//the cid value will map to the Content-Id of a Linked resource.
//thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo'
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:companylogo >", null, "text/html");
//create the LinkedResource (embedded image)
LinkedResource logo = new LinkedResource( "c:\\temp\\logo.gif" );
logo.ContentId = "companylogo";
//add the LinkedResource to the appropriate view
htmlView.LinkedResources.Add(logo);
//add the views
mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1"); //specify the mail server address
smtp.Send(mail);
}
Aug 8, 2012
How Parse XML Using Regular Expressions in Asp.net with C#
Kalpesh Satasiya
12:55 PM
ahmedabad, asp.net, software developer, software development, XML Parse
1 comment
Hello Friends,
I got good solution for XML element value find from XML string.
Need to just call this function with parameters XML string, XML element name and default value if value not find into XML string.
private String ExtractContentFromXml(String xml, String element, String defaultValue)
{
String RegExpression = String.Format(@"(?<={0}>)[\S\s]*?(?=\<\/{0})", element);
Match ThisMatch = Regex.Match(xml, RegExpression);
if (ThisMatch.Success)
return ThisMatch.Value;
else
return defaultValue;
}
I hope you will enjoy this solution...
Jan 6, 2012
Dec 15, 2011
How to restore database when database was suspect
Kalpesh Satasiya
5:12 PM
ahmedabad, cursor in sql server, software developer, software development, sql server database suspect, suspect database, web developer, web development
3 comments
ALTER DATABASE DataBaseName SET EMERGENCY
DBCC checkdb(DataBaseName)
ALTER DATABASE DataBaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (DataBaseName, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE DataBaseName SET MULTI_USER
Nov 30, 2011
Create Dynamic Excel file using Asp.Net
{
// make sure nothing is in response stream
response.Clear();
response.Charset = "";
// set MIME type to be Excel file.
response.ContentType = "application/ms-excel";
// add a header to response to force download (specifying filename)
response.AddHeader("Content-Disposition", "attachment; filename=\"MyFile.xls\"");
for (int i = 0; i < 10; i++)
{
// Send the data. Tab delimited, with newlines.
response.Write("Col1 \t Col2 \t Col3 \t Col4 \n");
}
// Close response stream.
response.End();
}
Nov 18, 2011
Parent Child Relationship on self table in sqlserver
Kalpesh Satasiya
3:41 PM
ahmedabad, parent child relation ship in sql server, self relation in sql server, software developer, software development, web developer
2 comments
(
EmpID int PRIMARY KEY,
EmpName varchar(30),
MgrID int FOREIGN KEY REFERENCES Emp(EmpID)
)
GO
Insert few record into table
INSERT dbo.Emp SELECT 1, 'President', NULL
INSERT dbo.Emp SELECT 2, 'Vice President', 1
INSERT dbo.Emp SELECT 3, 'CEO', 2
INSERT dbo.Emp SELECT 4, 'CTO', 2
INSERT dbo.Emp SELECT 5, 'Group Project Manager', 4
INSERT dbo.Emp SELECT 6, 'Project Manager 1', 5
INSERT dbo.Emp SELECT 7, 'Project Manager 2', 5
INSERT dbo.Emp SELECT 8, 'Team Leader 1', 6
INSERT dbo.Emp SELECT 9, 'Software Engineer 1', 8
INSERT dbo.Emp SELECT 10, 'Software Engineer 2', 8
INSERT dbo.Emp SELECT 11, 'Test Lead 1', 6
INSERT dbo.Emp SELECT 12, 'Tester 1', 11
INSERT dbo.Emp SELECT 13, 'Tester 2', 11
INSERT dbo.Emp SELECT 14, 'Team Leader 2', 7
INSERT dbo.Emp SELECT 15, 'Software Engineer 3', 14
INSERT dbo.Emp SELECT 16, 'Software Engineer 4', 14
INSERT dbo.Emp SELECT 17, 'Test Lead 2', 7
INSERT dbo.Emp SELECT 18, 'Tester 3', 17
INSERT dbo.Emp SELECT 19, 'Tester 4', 17
INSERT dbo.Emp SELECT 20, 'Tester 5', 17
GO
Create sql function
create FUNCTION [dbo].[ShowHierarchy]
(
@Root bigint
)
RETURNS
@menutable TABLE(EmpName varchar(max),MgrID int,EmpID int)
AS
BEGIN
DECLARE @EmpID int, @EmpName varchar(30),@MgrID int, @rootid bigint
set @rootid =@Root
SELECT @EmpID=EmpID,@EmpName=EmpName,@MgrID=MgrID FROM dbo.Emp WHERE EmpID = @Root
-- SET @EmpName = (SELECT EmpName FROM dbo.Emp WHERE EmpID = @Root)
if(@EmpName is not null)
begin
insert into @menutable select REPLICATE(' ', @@NESTLEVEL * 4) + @EmpName,@MgrID,@EmpID
end
SET @EmpID = (SELECT MIN(EmpID) FROM dbo.Emp WHERE MgrID = @Root)
WHILE @EmpID IS NOT NULL
BEGIN
insert into @menutable select * from dbo.ShowHierarchy(@EmpID)
SET @EmpID = (SELECT MIN(EmpID) FROM dbo.Emp WHERE MgrID = @rootid AND EmpID > @EmpID)
END
return
END
//call this function from where you want
Select * from dbo.ShowHierarchy(0)