Friday, May 2, 2008

check file extention of a file using C# Sanjeewa sapumana

//check file extention of a file using C# Sanjeewa sapumana

private bool CheckMediaFileExtention()
{
string UploadedMediaFileName = btnFileUploadSelectMediaFile.FileName;
string[] file = new string[2];
file= UploadedMediaFileName.Split('.');

if (file.Length < 2)
{
return false;
}

string fileext = file[1].ToLower();

if (fileext == "wmv" || fileext == "avi")
{
return true;
}
else
{
TrMessage.Visible = true;
lblError.Text = Constants.MSG_Notifications_EnterSpecifiedMovieFormat.ToString();
lblError.CssClass = Structures.MessegeTypeCSS.MessageError.ToString();
return false;
}

}

get the window closing event using javascript and calling method you required - Sanjeewa sapumana

window.onunload = abort;
function abort()
{
//your Java script or Ajax method as you like
StopMovie();
PlayMedia.UpdateTime(videoviewTime.toString());
}

Create Directery in c# coding is so easy like this - Sanjeewa Sapumana

System.IO.Directory.CreateDirectory(@"C:\New Folder");

create a property dataset for coding C# - Sanjeewa Sapumana

//This will provide easy and convenient way of using property C#

#region Properties

DataSet DsCourseList
{
get
{
if (dsCourseList == null)
{
try
{
Course objCourse = new Course();
DataSet dsTemp;
dsTemp = objCourse.GetAllExamPaperDetails();
if (dsTemp != null && dsTemp.Tables[0].Rows.Count > 0)
{
dsCourseList = dsTemp;
Session["dsCourseList"] = dsCourseList;
}
}
catch (Exception ex)
{
ex.Data.Add("UILayerException", this.GetType().ToString() + MyTutorErrorMesseges.Error_Seperator + "DataSet DsCourseList GEt {}");
Response.Redirect("../Error.aspx?LogId=" + MyTutorException.WriteEventLogs(ex, Constants.Database_Connection_Name, Master.LoggedUser.UserName), false);
}
}
return dsCourseList;
}
set
{
dsCourseList = value;
}
}

#endregion

add attribute to data rowbound of Datagrid (Confirmation java script) -Sanjeewa Sapumana

lb.Attributes.Add("onClick", "ExamConfirm('" + Constants.MSG_Notifications_ExamConfirmation.ToString() + "')");

Create List box item for Default value its quite simple like this

ddlVideos.Items.Insert(0, (new ListItem("--Select Video--", "0")));

Check file extention and validate Client side easily- Sanjeewa sapumana

<script language="javascript" type="text/javascript">

/*To check file extensions */
function checkFileExtension( s,e ){
parafilevalue =document.getElementById("FileUpload1").value
var file = parafilevalue.split('.');

var validType = false;

if( file.length < 2 )
{
return false;
}

var fileext = file[1].toLowerCase();

if( fileext == 'doc' || fileext == 'pdf'|| fileext == 'xls' || fileext == 'ppt'|| fileext == 'txt' )
{
validType = true;
}
if(validType==false)
{
alert("Please enter specified document type");
var who= document.getElementsByName('FileUpload1')[0];
var who2= who.cloneNode(false);
who2.onchange = who.onchange;
who.parentNode.replaceChild(who2,who);
}
return validType;

}
< /script >