Thursday, February 21, 2008

Upload Video in asp.net

First of all, by default, asp.net set the size is 4mb for each form request...if u want to upload larger file, u need to change the setting in web.config.

adding
between .

maxRequestLength is the maximum size of each form request
requestLengthDiskThreshold is the buffer size in server memory

before i didn't set executionTimeout, so the asp.net kills every request takes longer than 110seconds. so every time i upload the file takes longer than 2mins , it will comes up a not found page.....
set executionTimeout to allow the request time how long u want in seconds.

this method suppose is not good in uploading large files, it will spend all the server memory during upload progress. but in my project, there is only one person to upload the file, so it will not affect too much. But if so many people upload like youtube, hv to set sth like httphandle.....but i hvn't learn this, i think quite hard. btw, there is some control developed by company in order to handle this situation like PowUpload and KUpload. but not free.

then just use the control of FileUpload of asp.net.
and code:

aspx source:



code behind:
private bool CheckFileType(string fileName)
{
string ext = Path.GetExtension(fileName);
switch (ext.ToLower())
{
case ".rmvb":
return false;
default:
return true;
}
}
private void initialDataList()
{
string upFolder = MapPath("~/Video/VideoFiles/");
DirectoryInfo dir = new DirectoryInfo(upFolder);
DataList1.DataSource = dir.GetFiles();
DataList1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
initialDataList();
}
protected void btnAddVideo_Click(object sender, EventArgs e)
{
if (upVideo.HasFile)
{
if (CheckFileType(upVideo.FileName))
{
string filePath = "~/Video/VideoFiles/" + upVideo.FileName;
upVideo.SaveAs(MapPath(filePath));
}
}
initialDataList();
}

Load WebUserControl programmatically and Print it using session

Control _myControl;
protected void Page_Load(object sender, EventArgs e)
{
_myControl = LoadControl("SubContent1.ascx");
Arlyia_SubContent1 _subContent = (Arlyia_SubContent1)_myControl;
_subContent.XmlDataSourceXPath = "contents/content[@name='MainContent1']/subcontent[@name='SubContent1']/htmlcode[@language='"+Session["language"].ToString()+"']";
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(_myControl);
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Session["ControlsToPrint"] = _myControl;
//Response.Write("var printWindow = window.open('PrintWindow.aspx', 'PrintWindow'," + "'toolbars=no,status=no,width=300,top=10,left=10,height=300,resizable=no,scrollbars=no,menubar=no');");

//Control _myPrintingPageControl = LoadControl("~/PrintingPage/PrintingPageControl.ascx");
//PrintingPage_PrintingPageControl _printingPage = (PrintingPage_PrintingPageControl)_myPrintingPageControl;

//_printingPage.MyControl = _myControl;

//_printingPage.Page.RegisterClientScriptBlock("", "");

//PlaceHolder2.Controls.Add(_myPrintingPageControl);

//TextBox a = (TextBox)_printingPage.FindControl("TextBox1");
//a.Text = "shit";

Page.RegisterClientScriptBlock("", "");

//PlaceHolder bb = (PlaceHolder)_printingPage.FindControl("PlaceHoder1");
//bb = PlaceHolder1;

//Response.Write(bb.Controls[0].ToString());

//PlaceHolder bb = (PlaceHolder)_printingPage.FindControl("PlaceHoder1");
//bb.Controls.Add(a);
//Response.Redirect("~/PrintingPage/PrintingPage.aspx");
//_myControl.PlaceHoder.Controls.Add(a);
}

edit xml in xmldatasource

edit xml in xmldatasource

protected void Page_Load(object sender, EventArgs e)
{
//UpdatableXmlDataSource1.FilterXPath = "contents/content[@position='test']/htmlcode[@language='english']";
XmlDataSource1.XPath = "contents/content[@position='test']/htmlcode[@language='english']";
}
protected void Button1_Click(object sender, EventArgs e)
{
XmlNode node = XmlDataSource1.GetXmlDocument().SelectSingleNode("contents/content[@position='test']/htmlcode[@language='english']");
node.InnerText = "hihi";
XmlDataSource1.Save();
}

Retrieve the Html code for a Web User Control

public static string GetHtmlForControl(Control control)
{
StringWriter textwriter = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(textwriter);

control.DataBind();
control.RenderControl(writer);
string html = textwriter.GetStringBuilder().ToString();

return html;
}

Tip: If you're having problems with the generated Html being incomplete, then maybe you're calling the function above in the wrong time? I've been having some problems with databound EPiServer controls until we discovered that we were doing this too early. When we started doing it in the PreRenderComplete event of the page, then it started working:

protected void Page_PreRenderComplete(object sender, EventArgs e)
{
string html = FormHelper.GetHtmlForControl(Butikshuvud);
}

ASP.NET 2.0 Treeview - Expanding Nodes when Bound to SiteMap

The problem

A treenode can be selected or expanded. Selecting the node causes the SelectedNodeChange event to fire if the Treeview is configured correctly. Clicking the + icon on a node causes the TreeNodeExpanded event to fire. The selected event will not fire if the node is in Navigation mode. This behavior makes sense most of the time. The node is acting as a navigation link - it causes the browser to take you to a new page which means there is no postback. Your are going to a new page, without returning to the server first.

If the node has its NavigationUrl property set to an empty string, the node is in Selection mode. If the NavigationUrl is a non-zero length string ,the node is in Navigation mode.

For our project I wanted the children nodes to expand whenever the user selects a parent node. Yes, the user can click the + symbol to expand it, but our testing showed that many users expect the node to expand by clicking the node text instead. Since the nodes are in Navigation mode I couldn't put the code in the SelectedNodeChanged event.

My solution? Use the TreeNodeDatabound event to examine each node as it is being bound to the tree. If the current page URL matches the treenode NavigationUrl I expand all the of the current nodes children. It solves my problem. It still doesn't cause the SelectedNodeChanged to fire so it may not solve all your troubles. At least it's a start.

Protected Sub treeMainMenu_TreeNodeDataBound _
(
ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) _
Handles treeMainMenu.TreeNodeDataBound

' other binding code here...

If Request.Url.PathAndQuery = e.Node.NavigateUrl Then
e.Node.ExpandAll()
End If
End Sub

Saturday, October 6, 2007

i am trying to create a remote database in my home computer server. then move all connection to my home. Coz client 's computer need to install vpn when we demonstrate the website to the client if link to the school.

on fri i got 2 assignments to due, i can't do IE coding in this week. Sorry.

Friday, September 14, 2007

last two weeks

This two weeks, i was still developing the Arlyia System, i did the testimonial sub system, static content sub system, now i am developing the gift voucher sub system.
I code every day until mid night, sleep always at 3am, >.<.....But max is poorer than me, he even needs to stay overnight at monash, coz he didn't have Desktop and he feels that laptop slow down the developing progress.
Originally, gift voucher sub system should be done by Dennis, but he was sick, he even hasn't finish his photo gallery part as it should be finished last week. So i help to do managing part of gift voucher sub system to give him a start with.