Tuesday, November 16, 2010

Amazon web service ISBN Search

String DESTINATION = "https://ecs.amazonaws.com/onca/soap?Service=AWSECommerceService";
String MY_AWS_ID = "ACCESS_ID";
String MY_AWS_SECRET = "SECRET_ID";



ItemSearchRequest objRequest = new ItemSearchRequest();
objRequest.SearchIndex = "Books";
objRequest.Power = "ISBN:9780557230648";
objRequest.ResponseGroup = new string[] { "Small", "AlternateVersions", "Large", "Medium", "Offers" };
objRequest.Sort = "salesrank";



ItemSearchRequest[] requests = new ItemSearchRequest[] { objRequest };

ItemSearch itemSearch = new ItemSearch();
itemSearch.AWSAccessKeyId = MY_AWS_ID;
itemSearch.Request = requests;



// create an instance of the serivce
AWSECommerceService api = new AWSECommerceService();

// set the destination
api.Destination = new Uri(DESTINATION);

// apply the security policy, which will add the require security elements to the
// outgoing SOAP header
AmazonHmacAssertion amazonHmacAssertion = new AmazonHmacAssertion(MY_AWS_ID, MY_AWS_SECRET);
api.SetPolicy(amazonHmacAssertion.Policy());

// make the call and print the title if it succeeds
try
{

ItemSearchResponse response = api.ItemSearch(itemSearch);
Items info = response.Items[0];
Item[] items = info.Item;
for (int i = 0; i < items.Length; i++) { Label1.Text += "Book Title: " + items[i].ItemAttributes.Title.ToString() + "<br />";} } catch (Exception ex) { Label1.Text += ex.Message.ToString(); }

Note:-
==================================================
AmazonHmacAssertion class is available in client project of below link
http://associates-amazon.s3.amazonaws.com/signed-requests/samples/amazon-product-advt-api-sample-csharp-soap.zip

Wednesday, October 6, 2010

FileUpload with Updatepanel and PostbackTrigger not working at first time,

Page.Form.Attributes.Add("enctype", "multipart/form-data");

Tuesday, October 5, 2010

configure log4Net

Web.Config:-


under configsection

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>

<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="logs\\error_04112009.log" />
<param name="AppendToFile" value="true"/>
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} - %m%n" />
</layout>
</appender>
<logger name="File">
<level value="All" />
<appender-ref ref="LogFileAppender" />
</logger>
</log4net>


Global.asax:-

void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
}

Monday, September 27, 2010

Paging using SP

SET @StartRow = (@PageIndex - 1) * @PageSize + 1
SET @EndRow = @StartRow + @PageSize - 1

SET @StartRow = (@PageIndex - 1) * @PageSize + 1
SET @EndRow = @StartRow + @PageSize - 1

SET @TotalRec = Select Count(*) from Test

-- If StartRow is less then Total Records then fetch all records between startrow and endrow else ignore start row only consider endrow
IF @StartRow <= @TotalRecords SET @SQL = ' SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY '+@Sort+') as [RowNumber] from Test )T1 WHERE RowNumber >= @StartRow AND RowNumber <= @EndRow'

SET @ParmDefinition = N'@StartRow int,@EndRow int,@Sort nvarchar(50)';
EXECUTE sp_executesql @SQL,@ParmDefinition,@StartRow=@StartRow,@EndRow=@EndRow,@Sort=@Sort;

END
ELSE
BEGIN
SET @SQL = '
SELECT *
FROM (
SELECT *,
ROW_NUMBER() OVER (ORDER BY '+@Sort+') as [RowNumber]
from Test
)T1
WHERE RowNumber <= @EndRow'

SET @ParmDefinition = N'@StartRow int,@EndRow int,@Sort nvarchar(50)';
EXECUTE sp_executesql @SQL,@ParmDefinition,@StartRow=@StartRow,@EndRow=@EndRow,@Sort=@Sort;
END



RETURN @TotalRec

paging for repeater

if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
PagedDataSource pgitems = new PagedDataSource();
DataView dv = new DataView(ds.Tables[0]);
pgitems.DataSource = dv;
pgitems.AllowPaging = true;
pgitems.PageSize = int.Parse(hidPageSize.Value.ToString());
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 1)
{
rptTopPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++) pages.Add((i + 1).ToString()); rptTopPages.DataSource = pages; rptTopPages.DataBind(); } else { rptTopPages.Visible = false; } rptItem.DataSource = pgitems; rptItem.DataBind(); ASPX


<asp:Repeater ID="rptTopPages" runat="server" OnItemCommand="rptPages_ItemCommand">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr class="text">
<td>
<b>Page:</b>&nbsp;
</td>
<td>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage" CssClass="ActiveNode" CommandName="Page" Visible='<%# SetVisible(Container.DataItem,true) %>'
CommandArgument="<%# Container.DataItem %>" runat="server"><%# Container.DataItem %></asp:LinkButton><asp:Label
ID="lblPage" runat="server" Text='<%# Container.DataItem %>' CssClass="InActiveNode"
Visible='<%# SetVisible(Container.DataItem,false) %>'></asp:Label>&nbsp;
</ItemTemplate>
<FooterTemplate>
</td> </tr> </table>
</FooterTemplate>
</asp:Repeater>

Thursday, September 23, 2010

Use FormsAuthenticationTicket to save LoggedIn UserID

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2,id,DateTime.Now,DateTime.Now.AddMinutes(10), false, testid);

string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
HttpContext.Current.Response.Cookies.Add(cookie);


Fetch Data from FormsAuthenticationTicket :-


if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.AuthenticationType == "Forms")
{
System.Web.Security.FormsIdentity formsIdentity = default(System.Web.Security.FormsIdentity);
formsIdentity = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity;
string str = formsIdentity.Ticket.UserData;
}
}

Reflection + set/Get property

foreach (PropertyDescriptor properties in prop)
{
objClass.GetType().GetProperty(properties.Name).SetValue(objClass, objlistObject.GetType().GetProperty(properties.Name).GetValue(objlistObject, null), null);
}