by nolovelust
24. February 2010 22:58
Test from Windows Live Writer
1: public static string foo()
2: { 3: return foo;
4: }
a584a79d-b31c-43e2-9010-3d35472fd825|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags:
Random
by nolovelust
24. February 2010 18:07
i use below ajax function below that works with almost all new mobile phones to create better user experience on my mobile sites.
function toggleBox(divId, DivState) // 1 visible, 0 hidden
{
var objToggle = document.layers ? document.layers[divId] : document.getElementById ? document.getElementById(divId).style : document.all[divId].style;
objToggle.display = document.layers ? (DivState ? "show" : "hide") : (DivState ? "block" : "none");
}
/************************************************************\
*
\************************************************************/
function ajaxRequest(mydiv, myloadingdiv, url)
{
var ajaxRequestObject = false;
try
{
ajaxRequestObject = new XMLHttpRequest();
}
catch(err1)
{
try
{
ajaxRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(err2)
{
try
{
ajaxRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(err3)
{
document.getElementById(mydiv).innerHTML = 'No ajax support';
}
}
}
ajaxRequestObject.open('GET', url, true);
ajaxRequestObject.setRequestHeader('Content-Type', 'text/html');
ajaxRequestObject.onreadystatechange = function()
{
if(ajaxRequestObject.readyState == 4)
{
if(ajaxRequestObject.status==200)
{
toggleBox(myloadingdiv, 0);
document.getElementById(mydiv).innerHTML = ajaxRequestObject.responseText;
}
else
{
document.getElementById(mydiv).innerHTML = 'Could not retrieve data';
}
}
else
{
toggleBox(myloadingdiv, 1);
}
};
ajaxRequestObject.send();
}
you call the function like:
<a href="javascript:ajaxRequest('idofresultdiv','idofloadingindicatordiv','url.asp')">ajax</a>
3bc6508e-ca7c-4526-beef-458bf69b3ff5|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags:
by nolovelust
23. February 2010 15:42
If you are interested in mobile web as developer you've probably heard mobile advertising company Decktrade. Their parent company MillenialMedia announced that they have acquired mobile analytics company TapMetrics. Mobile ad space is getting hotter.
Here is the full press release.
Millennial Media, the largest independent mobile advertising network, announced today that it will acquire TapMetrics, a San Francisco-based mobile analytics firm, focused on application usage and behavior.
"The market has recognized Millennial Media as the leader in mobile advertising. As a result of their deep commitment to advertisers, they deliver the best business partnership and monetization for mobile companies - particularly developers," said Chris Brown, co-Founder and CEO, TapMetrics. "What is exciting to us is that Millennial Media now has the only scalable solution for developers that doesn't contain an operating system bias, making Millennial Media the natural partner for us."
Millennial Media operates the leading mobile advertising platform worldwide. Since adding $16M to its strong cash position in November, Millennial Media has expanded its offerings to key customer segments, to include OEM and platform partnerships that seek to access its strong base of developers and publishers. Additionally, Millennial Media's employee base has grown by more than 20%, as it continues to expand operations in the U.S. and Europe.
For more information on the deal, please visit: http://www.millennialmedia.com/2010/02/millennial-media-acquires-tapmetrics/
by nolovelust
19. February 2010 21:42
For my new project i needed to protect actual location of files on my server and send them to visitor via download page/handler. Below code is a collection of sources found on the internet.
It is a class with 3 different methods. All does same job with a different approach.
using System;
using System.IO;
using System.Web;
public class Download
{
public static void SmallFile(string filename, string filepath, string contentType)
{
try
{
FileStream MyFileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
long FileSize;
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
MyFileStream.Close();
HttpContext.Current.Response.ContentType = contentType;
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
HttpContext.Current.Response.BinaryWrite(Buffer);
}
catch
{
HttpContext.Current.Response.ContentType = "text/html";
HttpContext.Current.Response.Write("Downloading Error!");
}
HttpContext.Current.Response.End();
}
public static void LargeFile(string filename, string filepath, string contentType)
{
Stream iStream = null;
// Buffer to read 10K bytes in chunk
//byte[] buffer = new Byte[10000];
// Buffer to read 1024K bytes in chunk
byte[] buffer = new Byte[1048576];
// Length of the file:
int length;
// Total bytes to read:
long dataToRead;
try
{
// Open the file.
iStream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
// Total bytes to read:
dataToRead = iStream.Length;
HttpContext.Current.Response.ContentType = contentType;
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
// Read the bytes.
while (dataToRead > 0)
{
// Verify that the client is connected.
if (HttpContext.Current.Response.IsClientConnected)
{
// Read the data in buffer.
length = iStream.Read(buffer, 0, 10000);
// Write the data to the current output stream.
HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
// Flush the data to the HTML output.
HttpContext.Current.Response.Flush();
buffer = new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
//prevent infinite loop if user disconnects
dataToRead = -1;
}
}
}
catch (Exception ex)
{
// Trap the error, if any.
//HttpContext.Current.Response.Write("Error : " + ex.Message);
HttpContext.Current.Response.ContentType = "text/html";
HttpContext.Current.Response.Write("Error : file not found");
}
finally
{
if (iStream != null)
{
//Close the file.
iStream.Close();
}
HttpContext.Current.Response.End();
HttpContext.Current.Response.Close();
}
}
public static void ResumableFile(string filename, string fullpath, string contentType)
{
try
{
FileStream myFile = new FileStream(fullpath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
HttpContext.Current.Response.AddHeader("Accept-Ranges", "bytes");
HttpContext.Current.Response.Buffer = false;
long fileLength = myFile.Length;
long startBytes = 0;
//int pack = 10240; //10K bytes
int pack = 1048576; //1024K bytes
if (HttpContext.Current.Request.Headers["Range"] != null)
{
HttpContext.Current.Response.StatusCode = 206;
string[] range = HttpContext.Current.Request.Headers["Range"].Split(new char[] { '=', '-' });
startBytes = Convert.ToInt64(range[1]);
}
HttpContext.Current.Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0)
{
HttpContext.Current.Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength));
}
HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");
HttpContext.Current.Response.ContentType = contentType;
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int)Math.Floor((double)((fileLength - startBytes) / pack)) + 1;
for (int i = 0; i < maxCount; i++)
{
if (HttpContext.Current.Response.IsClientConnected)
{
HttpContext.Current.Response.BinaryWrite(br.ReadBytes(pack));
}
else
{
i = maxCount;
}
}
}
catch
{
HttpContext.Current.Response.ContentType = "text/html";
HttpContext.Current.Response.Write("Error : file not found");
}
finally
{
br.Close();
myFile.Close();
}
}
catch
{
HttpContext.Current.Response.ContentType = "text/html";
HttpContext.Current.Response.Write("Error : file not found");
}
}
}
9996ed35-8ba2-4231-9cf4-09d9f852cdb9|5|4.8|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags:
ASP.NET | Open Source
by nolovelust
19. February 2010 21:39
I have decided to open source code of http://phn.me to public.
For more info check project site at http://mobilesitecreator.codeplex.com/
and http://phn.me/opensource.htm
Mobile site creator is a .net 3.5 c# project and it is mobile enabled .
You can host subdomain based mobile sites that manageable via any mobile phone.
Some of it’s features are:
One of the most advanced mobile web designer
Earn money from adverts with the help of companies like Admob, Mojiva, Buzzcity etc.
HTML allowed to design your site manually
Use style sheets to design your site
Code snippets
Link rotator add-on
Re-publish RSS feeds add-on
Guestbook add-on
Poll and Quiz add-on
Chat add-on
Email to admin add-on
Online visitor list add-on
Show visitors' country and flag add-on
Insert images from Flickr and videos from Youtube to your site
Forums to get help from fellow wapmasters
And many more...
Setup is very simple:
Open web.config file remove default domains and add your own domains . Rest of the settings pretty self explanatory such as allowed file types for upload and allowed file limit.
You need to setup wild card dns setup on your domain(s) in order to get sub domain system working.
You also need to setup a web site on iis without host headers if you will use more than one domain to serve sites. If you are using iis7 app needs to be on classic app pool due to limitation of URLRewriter
For caching rss feeds and flicker search results you need to have write access to apps root folder.
App uses 2 sql server databases, one is for content and user info the other is to host binary files. I have used sql server to store binary uploads for easy file management. It doesn't affect the performance as current setup gives only 5 mb space to each user.
I have provided full database script in /AppData/Db scripts folder. If you change name of PHNfileStore.mdf database make sure you alter trigger in users table of PHN.mdf . Trigger there deletes files of user when user removed from database
Once site up and running create to create your global admin account just register a user and set its isGlobalAdmin status to true from your sql database. This is required to manage global settings such as database cleanup,backup,setting up paid user status,checking/removing illegal sites
Please keep in mind that i am beginner to .net and there could be place for many improvements in the code