Posts

Showing posts from November, 2013

return a file, c#, asp.net

string filename = "myfile.typ";
string fileStr = "";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] bytes = encoding.GetBytes(fileStr);
//or any other way to serialize your file

Response.Clear();
Response.ContentType = "application/ics;charset=utf-8";
//the general rule is (1) google (2) application/fileType (3) if is text then text/fileType
Response.AddHeader("content-disposition", "inline;filename=" + filename);
Response.BinaryWrite(bytes);
Response.End();
Response.Flush();

usefull CSS tricks and tips

1. Style a Dropdown / Select:
http://stackoverflow.com/questions/11185906/select-box-arrow-style/20129901#20129901

2. Style Checkboxes and Radio:
http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/
the point is to hide the inputs and put spans with background images instead and use js to change the background-position at need.

Costumize Facebook, Twitter ad Google Plus Sharing

Facebook : beyond the great api they give for extra stuff they are the only ones still allowing title, description and image via href so the code is like this

function OpenFacebookShare(title, summary, url, imageUrl) {
  var url = 'http://www.facebook.com/sharer.php?s=100&p[title]=' +
        encodeURIComponent(title) +
    '&p[summary]=' + encodeURIComponent(summary) +
    '&p[url]=' + encodeURIComponent(url) +
    '&p[images][0]=' + encodeURIComponent(imageUrl);
    window.open(url, 'mywindow', 'menubar=1,resizable=1,width=650,height=450');
};

as simple as that.


Twitter: twitter only allows url and text (only 140 chars) by href.
but they do request the url for their own meta tags, i.e. "twitter:title" ect.

to do this you must create a twitter account and create a "card" for your domain and allow that domain. its really not that much of a horror, just create an account, go here https://dev.twitter.com/docs…

Xml to Excel Via Xsl

there is a nice trick in XSL that allows us to Create XLS documents. therefor taking any object, serializing it to XML and then using the right XSL we will get our XLS just as we want it, so there is the XSL.

notice that if you serialize objects that comes from services the usually come with some
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://xmlns.bla/bla/yourType")]

and if so the XML nodes will look like this
<node xmlns="http://xmlns.bla/bla/yourType">20:52:00</node>

and for some reason it wont read the nodes, so the solution is
allXmlStr = allXmlStr.Replace("xmlns=\"http://xmlns.bla/bla/yourType\"", "");

<xsl:stylesheetversion="1.0" 
xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:user="urn:my-scripts"