How to write two Handlers using Switch Case - asp.net

i wrote two handlers but i need to write now only one handler using switch case how to write i tried but not working. please help me. this is my two handlers code i want that in switch case.please solve this problem
public void ProcessRequest(HttpContext context)
{
string fname = string.Empty;
string ffname = string.Empty;
string m_Result = string.Empty;
DataTable dt = new DataTable();
Guid id = Guid.NewGuid();
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
ffname = "~/Adds_uploads/" + fname;
}
string p = Path.GetFileNameWithoutExtension(fname);
fname = Path.Combine(context.Server.MapPath("~/Adds_uploads/"), p);
file.SaveAs(fname + id + Path.GetExtension(ffname));
string dirName1 = new DirectoryInfo(fname).Name;
FileInfo fInfo = new FileInfo(ffname);
String dirName = fInfo.Directory.Name + '/' + dirName1 + id + Path.GetExtension(ffname);
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(dirName));
//RAID = context.Request.QueryString["RA_ID"].ToString();
//UploadFileToDB(file, RAID);
}
}
}
public bool IsReusable {
get {
return false;
}
}
2nd Handler
public void ProcessRequest(HttpContext context)
{
string fname = string.Empty;
string ffname = string.Empty;
string m_Result = string.Empty;
DataTable dt = new DataTable();
Guid id = Guid.NewGuid();
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
ffname = "~/Fileuploads/" + fname;
}
string p = Path.GetFileNameWithoutExtension(fname);
fname = Path.Combine(context.Server.MapPath("~/Fileuploads/"), p);
file.SaveAs(fname + id + Path.GetExtension(ffname));
string dirName1 = new DirectoryInfo(fname).Name;
FileInfo fInfo = new FileInfo(ffname);
String dirName = fInfo.Directory.Name + '/' + dirName1 + id + Path.GetExtension(ffname);
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(dirName));
//RAID = context.Request.QueryString["RA_ID"].ToString();
//UploadFileToDB(file, RAID);
}
}
}
public bool IsReusable {
get {
return false;
}
}

I think the only difference if the upload path. I would suggest you to pass along another input form the view and then determine the upload path based on that.
i.e
you would have
//for case one
<input type='hidden' name='uploadType' value='files' />
//for case two
<input type='hidden' name='uploadType' value='adds' />
inside your individual file upload forms and then on your action method you can just use
var mappedDirectory = HttpContext.Current.Request.Form["uploadType"].ToString() == "adds" ? "~/Adds_uploads/" : "~/Fileuploads/";
and use this string in your fname construct. So your new method would be like
public void ProcessRequest(HttpContext context)
{
var mappedDirectory = HttpContext.Current.Request.Form["uploadType"].ToString() == "adds" ? "~/Adds_uploads/" : "~/Fileuploads/";
string fname = string.Empty;
string ffname = string.Empty;
string m_Result = string.Empty;
DataTable dt = new DataTable();
Guid id = Guid.NewGuid();
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
ffname = mappedDirectory + fname;
}
string p = Path.GetFileNameWithoutExtension(fname);
fname = Path.Combine(context.Server.MapPath(mappedDirectory), p);
file.SaveAs(fname + id + Path.GetExtension(ffname));
string dirName1 = new DirectoryInfo(fname).Name;
FileInfo fInfo = new FileInfo(ffname);
String dirName = fInfo.Directory.Name + '/' + dirName1 + id + Path.GetExtension(ffname);
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(dirName));
//RAID = context.Request.QueryString["RA_ID"].ToString();
//UploadFileToDB(file, RAID);
}
}
}

Related

I am working with asp.net and i try to display multiple div dynamically it working but every time display same slider data

#region fillAllData4
private void fillAllData4()
{
clsCategory objCategory = new clsCategory(true);
clsProductMain objProduct = new clsProductMain(true);
objCategory.getDropDownMenu();
objProduct.getProduct();
string str = string.Empty;
int i = 0;
// int j = 0;
if (objCategory.ListclsCategory.Count > 0)
{
for (i = 0; i < objCategory.ListclsCategory.Count; i++)
{
cat.InnerHtml = objCategory.ListclsCategory[0].CategoryName;
cat1.InnerHtml = objCategory.ListclsCategory[1].CategoryName;
cat2.InnerHtml = objCategory.ListclsCategory[2].CategoryName;
cat3.InnerHtml = objCategory.ListclsCategory[3].CategoryName;
string[] filePaths = Directory.GetFiles(Server.MapPath("~/images/Saree/"));
int j = 0;
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
str += #"<div><div><img class='imges' src='images/Saree/" + fileName + #"' /></div>
<div class='sname'>" + objProduct.ListclsProductMain[j].ProductName + #"</div>
<div class='sname2'>" + objProduct.ListclsProductMain[j].MRP + #"</div></div>";
j++;
}
slider3.InnerHtml = str;
slider4.InnerHtml = str;
slider5.InnerHtml = str;
slider6.InnerHtml = str;
//System.Web.UI.HtmlControls.HtmlGenericControl createDiv =
//new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
//createDiv.ID = "createDiv";
//createDiv.InnerHtml =str;
//this.Controls.Add(createDiv);
}
}
}
#endregion

Error: Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation

I want to display Agendas from table "tblAgenda" using Asp.net here is the query:
public static List<int> SelectByYear()
{
DbManager db = new DbManager();
try
{
List<int> list = new List<int>();
var result = from p in db.tblAgenda
group p by p.News.Value.Year
into g
select new { Year = g.Key, Releases = g };
foreach (var obj in result)
{
list.Add(obj.Year);
}
list.Reverse();
return list.ToList<int>();
}
catch
{
return null;
}
finally
{
db.Dispose();
}
}
and here I am calling the above method:
public partial class edd_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Request.QueryString["id"]))
{
RecentData();
}
}
}
private void RecentData()
{
List<tblAgenda> agd = new List<tblAgenda>();
StringBuilder sbHeadings = new StringBuilder();
StringBuilder sbData = new StringBuilder();
List<int> list1 = AgendaManager.SelectByYear();
if (list1 != null)
{
List<int> list = list1.Take(3).ToList<int>();
int Row = 0;
string RowCss = "";
foreach (tblAgenda ob in agd)
{
strYears = "";
if (list.Count > 0)
{
Table tblHead = new Table();
TableRow trHead = new TableRow();
TableCell tcDvHead = new TableCell();
TableCell tcLnkHead = new TableCell();
for (int i = 0; i < list.Count; i++)
{
Row = 0;
List<clsAgenda> listData = new List<clsAgenda>();
listData = null;
DateTime dt = DateTime.Now.AddYears(1);
string stryr = strYears;
int intyr = Convert.ToInt32(list[i]);
diff = Convert.ToInt32(dt.Year) - Convert.ToInt32(intyr);
if (diff == 0 || diff == 1 || diff == 2)
{
if (drpDepartments.SelectedValue == "-1")
{
strYears += list[i] + ",";
sbHeadings.Append("<div id='dv" + list[i] + "' style='float:left;width:60px;cursor:pointer;' class='btnclass11'>" + list[i] + "</div><div style='float:left;'> </div>");
listData = AgendaManager.SelectAllByYear(Convert.ToInt32(list[i]));
}
else
{
if (AgendaManager.IsAgendExistForDeptartment(Convert.ToInt32(list[i]), Convert.ToInt64(drpDepartments.SelectedValue)))
{
strYears += list[i] + ",";
sbHeadings.Append("<div id='dv" + list[i] + "' style='float:left;width:60px;cursor:pointer;' class='btnclass11'>" + list[i] + "</div><div style='float:left;'> </div>");
}
listData = AgendaManager.SelectAllByYear(Convert.ToInt32(list[i]), Convert.ToInt64(drpDepartments.SelectedValue));
}
sbData.Append("<table id='tbl" + list[i] + "' cellspacing='1' cellpadding='4' width='885' style='display:none;margin-top:10px;' class='GridBorder' >");
sbData.Append("<tr class='GridViewHeaderStyle' >");
sbData.Append("<th style='width:380px;height:22px;text-align:left;'>Meeting</th><th style='height:22px;text-align:left;'>Date</th><th style='width:70px;height:22px;text-align:left;'>Time</th><th style='width:70px;height:22px;text-align:left;'>Agenda</th><th style='height:22px;text-align:left;width:120px;'>Web Cast</th><th style='height:22px;text-align:left;width:100px;'>Minutes</th>");
sbData.Append("</tr>");
foreach (clsAgenda obj in listData)
{
RowCss = "";
if (Row == 1)
{
RowCss = "class='GridRow'";
}
sbData.Append("<tr " + RowCss + ">");
sbData.Append("<td >" + obj.Title + "</td>");
sbData.Append("<td >" + string.Format("{0:MMM dd, yyyy}", obj.AgendaDate) + "</td>");
sbData.Append("<td >" + obj.Time + "</td>");
sbData.Append("<td ><a style='color:black;' href='agenda.aspx?id=" + obj.ID + "'>View</a></td>");
if (string.IsNullOrEmpty(obj.WebCast))
{
sbData.Append("<td >---</td>");
}
else
{
sbData.Append("<td ><a style='color:black;' href='" + obj.WebCast + "'>" + obj.WebCastTitle + "</a></td>");
}
if (string.IsNullOrEmpty(obj.MinutesFile))
{
sbData.Append("<td >---</td>");
}
else
{
if (ob.showThroughBroswer == 1)
{
sbData.Append("<td ><a href='downloadfile.aspx?AgendaMinuteId=" + obj.ID + "' target='_blank'>View</a></td>");
}
else
{
sbData.Append("<td ><a href='showpdf.aspx?AgendaMinuteId=" + obj.ID + "' target='_blank'>View</a></td>");
}
}
sbData.Append("</tr>");
Row++;
if (Row == 2)
{
Row = 0;
}
}
sbData.Append("</table>");
}
else
break;
}
if (strYears.Length > 0)
{
strYears = strYears.Substring(0, strYears.Length - 1);
}
strFirstYear = list[0].ToString();
tcDvHead.Text = sbHeadings.ToString();
if (diff == 1 || diff == 2)
{
tcLnkHead.Text = "<div class='dvhrfclass'><a href='listagendas.aspx?id=pre' class='link1'>Previous Meetings >></a></div>";
}
else
{
tcLnkHead.Text = "";
}
trHead.Cells.Add(tcDvHead);
trHead.Cells.Add(tcLnkHead);
tblHead.Rows.Add(trHead);
StringWriter sW = new StringWriter();
HtmlTextWriter hW = new HtmlTextWriter(sW);
tblHead.RenderControl(hW);
letHeading.Text = sW.ToString();
letData.Text = sbData.ToString();
}
}
}
}
now the issue is I am getting no values in list1, I have tried using the debugger on the query and found that I can't access the "tblAgenda", its giving an error that: " Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation". I have searched alot but didn't find anything good, my connection string is totally fine because all the other tables are working fine even in "tblAgenda" I can store new agenda from admin panel but I can't retrieve the agendas on front end, what is the issue here?
Thanks.

Cutting and saving video in folder using ffmpeg

private bool ReturnVideo(string fileName)
{
string html = string.Empty;
//rename if file already exists
int j = 0;
string AppPath;
string inputPath;
string outputPath;
// string imgpath;
AppPath = Request.PhysicalApplicationPath;
//Get the application path
inputPath = AppPath + "OriginalVideo";
//Path of the original file
outputPath = AppPath + "ConvertVideo";
//Path of the converted file
// imgpath = AppPath + "Thumbs";
//Path of the preview file
string filepath = Server.MapPath("~/OriginalVideo/" + fileName);
while (File.Exists(filepath))
{
j = j + 1;
int dotPos = fileName.LastIndexOf(".");
string namewithoutext = fileName.Substring(0, dotPos);
string ext = fileName.Substring(dotPos + 1);
fileName = namewithoutext + j + "." + ext;
filepath = Server.MapPath("~/OriginalVideo/" + fileName);
}
try
{
this.fileuploadImageVideo.SaveAs(filepath);
}
catch
{
// return false;
}
string outPutFile;
outPutFile = "~/OriginalVideo/" + fileName;
int i = this.fileuploadImageVideo.PostedFile.ContentLength;
System.IO.FileInfo a = new System.IO.FileInfo(Server.MapPath(outPutFile));
string cmd = "-y -ss 00:00:00 -to 00:00:10 -i " + inputPath + "\\" + fileName + " -vcodec copy -acodec copy " + outputPath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".mp4";
ConvertNow(cmd);
return true;
}
private void ConvertNow(string cmd)
{
string exepath;
string AppPath = Request.PhysicalApplicationPath;
//Get the application path
exepath = AppPath + "ffmpeg\\ffmpeg.exe";
Process proc = new Process();
proc.StartInfo.FileName = exepath;
//Path of exe that will be executed, only for "filebuffer" it will be "flvtool2.exe"
proc.StartInfo.Arguments = cmd;
//The command which will be executed
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
//while (proc.HasExited == false)
//{
//}
}

Java servlet - export to an excell using string buffer

I am new to JAVA. I am trying to export Excel through servlet from resultset.
When i am trying to store data in String buffer the it is not actually saving it.
Testfirst.java
String assingee_name = req.getParameter("firstName");
String track_name = req.getParameter("track");
String sla_id = req.getParameter("sla");
StringBuffer sb = new StringBuffer();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Databasethree");
stmt = con.createStatement();
//pw.println("'" +assingee_name + "'");
length = track_name.length();
if (length > 0) {
rs = stmt.executeQuery("SELECT* FROM casedetails where track =" + "'" + track_name + "'");
}
length = sla_id.length();
if (length > 0) {
//rs = stmt.executeQuery("SELECT* FROM casedetails where case_age >"+"'" +sla_id + "'");
rs = stmt.executeQuery("SELECT* FROM cdoscase where Incident_Submit_Fiscal_Year=" + "'" + sla_id + "'");
}
length = assingee_name.length();
if (length > 0) {
rs = stmt.executeQuery("SELECT* FROM casedetails where Assingee_name =" + "'" + assingee_name + "'");
}
pw.println("<html><body>");
pw.println("<H1> CDOS Case Management Version 1.1 </H1>");
pw.println("<Head><style>table,th,td{border:1px solid black;}</style></head>");
pw.println("<table>");
ResultSetMetaData rm = rs.getMetaData();
int clm = rm.getColumnCount();
StringBuffer sb1 = new StringBuffer();
String sb2 = new String();
for (int j = 1; j <= clm; j++) {
sb2 = rm.getColumnName(j);
pw.println("<th>");
pw.println(sb2);
pw.println("</th>");
}
ArrayList Rows = new ArrayList();
ArrayList row = new ArrayList();
Object a = new Object();
int jj = 0; // to find out the number rows
while (rs.next()) {
jj = jj + 1;
pw.println("<tr>");
for (int i = 1; i <= clm; i++) {
//data1[i]=rs.getString(i);
pw.println("<td>");
//pw.println(rs.getObject(i).toString());
pw.println(rs.getString(i));
pw.println("</td>");
sb2.append(rs.getString(i);
//row.add(rs.getString(i));
//sb2=sb2+rs.getObject(i).toString();
}
pw.println("</tr>");
} sb1.append("fd");
//Rows.add(row);
pw.println("Total Records found" + sb1);
pw.println("</table>");
//sb2=sb2+rs.getObject(clm).toString();
//sb1.append(sb2);
//sb1.append(sb2);
a = rs.getString(4).toString();
pw.println("this is data " + a);
pw.println("<p>");
pw.println("<td>Do you want to download report </td>");
req.setAttribute("data", Rows);
pw.println("<input type=\"submit\" name =\"submit1\" value=\"Export To Excel\">");
pw.println("</form>");
} catch (SQLException e) {
pw.println(e.getNextException());
} catch (ClassNotFoundException e) {
pw.println(e.getException());
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (con != null) {
con.close();
con = null;
}
} catch (Exception e) {
pw.close();
}
}
}
Any help on this is highly appreciated.
Thanks,
SR

MailEnable - Create Account

I'm trying to create an e-mail with MailEnable
based http://www.mailenable.com/developers/NET_SignUp.zip
MailEnable.Administration.Login oLogin = new MailEnable.Administration.Login();
oLogin.Account = iCliente.URL;
oLogin.LastAttempt = -1;
oLogin.LastSuccessfulLogin = -1;
oLogin.LoginAttempts = -1;
oLogin.Password = txt_Senha.Text;
oLogin.Rights = "";
oLogin.Status = -1;
oLogin.UserName = txt_Email + "#" + iCliente.URL;
if (oLogin.GetLogin() != 1)
{
oLogin.LastAttempt = 0;
oLogin.LastSuccessfulLogin = 0;
oLogin.LoginAttempts = 0;
oLogin.Password = txt_Senha.Text;
oLogin.Rights = "USER";
oLogin.Status = 1;
}
MailEnable.Administration.Mailbox mailBoxCreate = new MailEnable.Administration.Mailbox();
mailBoxCreate.Postoffice = iCliente.URL;
mailBoxCreate.MailboxName = txt_Email.Text;
mailBoxCreate.RedirectAddress = txt_Redirect.Text;
mailBoxCreate.RedirectStatus = 0;//recuperar valor da checkbox
mailBoxCreate.Limit = 51200; //-1 for unlimited
mailBoxCreate.Status = 1;
mailBoxCreate.AddMailbox();
MailEnable.Administration.AddressMap mailAMap = new MailEnable.Administration.AddressMap();
mailAMap.Account = iCliente.URL;
mailAMap.DestinationAddress = "[SF:" + iCliente.URL + "/" + txt_Email.Text + "]";
mailAMap.SourceAddress = "[SMTP:" + txt_Email.Text + "#" + iCliente.URL + "]";
mailAMap.AddAddressMap();
But does not work, it creates the email but no password!
:(
Follow my class running perfect.
using System;
using System.Data.SqlClient;
using System.IO;
using System.Xml.XPath;
using MailEnable;
namespace BLL
{
public class MailEnable_Geral
{
public string _Email { get; set; }
public bool CriarEmail(string _senha, string _redirect, long _ativarRedirect)
{
string[] vPostoffice = _Email.Split('#');
string _username = vPostoffice[0];
string _postoffice = vPostoffice[1];
string _domain=_postoffice;
bool _retorno = true;
try
{
MailEnable.Administration.Mailbox mb = new MailEnable.Administration.Mailbox();
mb.Postoffice = _postoffice;
mb.MailboxName = _username;
mb.Host = _domain;
mb.Limit = 51200;//50MB
mb.RedirectAddress = _redirect;
mb.RedirectStatus = _ativarRedirect;//Ativa ou desativa Redirect
mb.Status = 1;
mb.AddMailbox();
MailEnable.Administration.Login login = new MailEnable.Administration.Login();
login.Account = _postoffice;
login.Description = _username + " at " + _domain;
login.Host = _domain;
login.Rights = "USER";
login.Status = 1;
login.Password = _senha;
login.UserName = _username + "#" + _postoffice;
login.AddLogin();
MailEnable.Administration.AddressMap map = new MailEnable.Administration.AddressMap();
map.Account = _postoffice;
map.DestinationAddress = "[SF:" + _postoffice + "/" + _username + "]";
map.SourceAddress = "[SMTP:" + _username + "#" + _domain + "]";
map.Scope = "";
if (map.AddAddressMap() == 0)
{
throw new Exception("Failed address map");
}
}
catch (Exception e)
{
_retorno = false;
}
return _retorno;
}
}
}

Resources