Web Dev Matters and Me

Web Development Matters - HTML, XML, C#, .NET, AJAX/Javascript(jQuery), CSS, XML-XSLT

ME - LIFE,Philippines, Tokyo, ECE, PhilNITS/JITSE,情報処理, 日本語

things about Philippines, gaming, C# development and web development, how to make money in stock trading

Web Dev Matters and Me
Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Using Null values in SqlParameters Parameters.AddWithValue method.../ Stock Picks 2013


DEV/STOCKS

The XML page cannot be displayed - Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. Access is denied. Error processing resource

The XML page cannot be displayed - 
Cannot view XML input using XSL style sheet.
 Please correct the error and then click the Refresh button, or try again later.


 Access is denied. Error processing resource




On my continued experiment on dynamic XSLT website. It seems that the browsers WILL NOT PROCESS XSL stylesheets if the URL in the href attribute is different to the current document's URL because of cross-domain issue. Although I understand that if they don't do this, every pages might end up X-Domain attacked, but having it denied even on same DOMAIN is just absurd...




So, if you got an XML laced with 


< ?xml-stylesheet type="text/xsl" href="http://sitename.com/index.xsl"?>






on any xml documents in http://sitename.com/myxmlfile.xml




the referenced stylesheet will be processed, but if your site does something like SEO optimization and handles specific file by subdomain...




< ?xml-stylesheet type="text/xsl" href="http://internal.sitename.com/index.xsl"?>






this will display for any xml documents under internal.sitename.com/myxmldoc.xml ... 






So, the browsers got a narrow understanding of cross-domains, treating it as cross-URL. It should be called Cross URL instead of cross domain protection.












 

C# - Windows form Combobox displays System.Data.DataRowView Instead of Display Member

I'm getting a query result, in terms of a DataTable/DataSet. Now, the problem here is that, on my ComboBox object, I already specified the display member and the value member. I'm also sure that the datatable/dataset has that column in the result.
 
Although I set all of these properties I still get "System.Data.DataRowView" displayed on all items.

Once an Item is displayed for the first time the value is OK but when I choose another item and the selected Item become inactive, its displayed text would show  "System.Data.DataRowView". 

I tried all the bindings, reset the selected index... but alas, to no avail.


Then, I realized that the part making it display all those System.Data.DataRowView is from the SelectedIndexChanged event. An exception there is preventing the binding to work properly. Correcting the code there fixed it.

FTP Upload using C# The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

This error just bumped into me while working with 2 web hosting company. I had almost identical deployment setup for two website. Then, I have a main FTP account that I use to transfer all the files in the server. But I really don't want to use this FTP account as it has a right to the root folder, so I created another FTP account that only has access to a certain folder. This way, I am setting up a little security on the website.

But when I am test deploying my website, I get errors whenever the GetRequestStream method of the FtpWebRequest object.


The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

Which was weird, because I have done this before on the website with my main FTP account. Whenever I will access the ftp site with explorer, I also can't connect. 

After googling a lot of failed solutions, I decided to try few things on my own. I tried to add folder similar to the folder structure in the root (so it looks like MainFolder/SubFolder/MainFolder/SubFolder) .


Then I tried to run my application again and I'm able to add the file smoothly.
I don't like the workaround because I simply tells me to update the already built code and perform another round of testing..

I hope the web hosting company can still find a way... Workaround is OK, but it is a lame excuse.

Setting Datagridview TexboxCell into multiline mode like a Textbox control

Once again, I'm having my sleepless afterwork stress... so I decided to open my computer and do some dev work to lessen the remaining task before deployment and content writing.

Fortunately, we can also set the texbox like column in datagridview control to be a multiline textbox, without adding codes to cast our controls.. All with the use of designer view. On the datagridview control, we have to locate the Collection property and choose the desired datagridviewtextboxcolumn. From there, we navigate on the DefaultCellStyle property and set the WrapMode to true.

Also, we have to set the AutoSizeRowsMode of the datagridview control to AllCells. 

After this, when we add or type contents to the cell, it will expand automatically. Sweet, isn't it?

Adding stylesheet to XML document.

I am currently working on a web enhancement where XML datas are passed on the response object. It seems that the website will serve as a service point for some request. Since it is in XML format, it can be consumed by some applications with minimal parsing. Even with javascripts and XSLT too, which makes it really flexible.

Right after it is fetched from the database, the result is in Scalar form XML, thanks to SQL's XML PATH, which removes XML parsing from data resultset.

Doing this with XML LINQ is pretty easy.

XDocument xml = XDocument.Parse(stringFromDataBaseScalarResult);
var pi = new XProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"yourxslfile.xsl\"");
xml.Root.AddBeforeSelf(pi);
doc.Save(Response.Output);




or without LINQ




XmlDocument xml = new XmlDocument();
xml.LoadXml(stringFromDataBaseScalarResult);
XmlProcessingInstruction pi = xml.CreateProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"yourxslfile.xsl\"");
xml.InsertBefore(pi,xml.DocumentElement);
xml.Save(Response.Output);


I have to find some better clean way on the second one, because my initial attempt using Append method placed the processing instruction at the bottom of the xml document, although the stylesheet is still applied. It is an eyesore to some. (including me... hehe).

 



 

Enabling MS Office Application in Silverlight

I had this task of making a proof of concept sample that will allow users to use the User-Rich text editor Microsoft Word. 

It is really challenging, since working with those object are not something we can do in a jiffy , well at least for someone like me who rarely do MSWord macro things.

Reading thru API and using the new features of C#4.0 thru dynamic types, I'm able to design and implement a class library that can simply use MS Word and perform saving to database. It involves checking MRU and also subscribe to events of the MS Word Interop object. 

Since it is in Silvelight, data access and operations should be thru WCF. I completed the solution, and only later figured out that my ADO.NET class won't work in silvelright.


(x_x) <= sick due to stress

C# Code Optimizations

Today, I asked few developers from a forum(S.O) about some conversion. On my post, I said my need to get the data by performing bit shifts instead of divisions. Though, most of the people there suggested that it is not something that can improve optimization, I strongly disagree.


So, to make an experiment.. how about trying to make two Stopwatch objects ..
on the method that will be executed, initialize an instance, then invoke the Start method. just below that have a loop that performs 10000 times and inside this loop, perform a multiply operation.

After it exits the loop, invoke the Stop method.

then, on the next line, initialize the second Stopwatch object, invoke the start method and have a loop that performs 10000 times and inside this loop, perform a division operation.

after it exits the loop, invoke the Stop method of this object as well...


You can see the difference by checking on the ElapsedTicks of the Stopwatch objects.. I'm sure you now know what I'm talking about (^_^)



Getting reference to Controls in Lightswitch

While trying something in Lightswitch, we encountered a problem that involves using different controls (non-default), like Textbox,Stackpanels, etc. Now, the problem is, the data that will be displayed using those custom controls are not really part of the actual data model.

To Cache or Not To Cache - ASP.NET

I've recently implemented caching on some pages of my website. But it seems that caching won't help much because it is hosted on a shared server. While the page will be optimized using the cache, it can also be a reason to hit a 503 very soon, especially if caching is implemented with varying parameters.


But when should we use caching? I think caching can only solve scenarios to lessen the delay of serving resources to client browsers, instead of having a direct query to resources per request.

For example, I need to display data from database that takes about 1-2 minute query. This data can just be cached to have it served right away. But also, we should keep in mind that, if we put this on cache, we are putting these on memory..... and these memory takes a portion of the application pool's resource.

So, it is important to consider what to cache, and if the server (app pool) can cache.

The questionable Question Mark (?) in C#

This under-rated character can make writing C#(or Perl) codes easier and simple.

It can either be a comparator or a null-conditional if-else statement, in just a single line.

it can simplify 

string SampleText;

if(Datetime.Now.Month == 12)
{
SampleText = "Christmas Month";
}
else
{
SampleText = "Some Other Month";
}


into

string SampleText = Datetime.Now.Month == 12 ? "Christmas Month" : "Some Other Month";


or much even this

string SampleText;

if(passedParameter != null)
{
SampleText = passedParameter;
}
else if (passedParameter1 != null)
{
SampleText = passedParameter1;
}
else if (passedParameter2 != null)
{
SampleText = passedParameter2;
}
else if (passedParameter3 != null)
{
SampleText = passedParameter3;
}
else
{
SampleText = string.Empty;
}
to simple



string SampleText = passedParameter ?? passedParameter1 ?? passedParameter2 ?? passedParameter3 ?? String.Empty;


and this is not limited to strings, it also applies to Objects.


More to share as we go to the world of coding (^-^)

FB Connect