Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
pblm is in dis code dat utf8 and unicode format file is not getting uploaded, code is working only for ANSI format file. I want to upload all type of format file using dis code whatever ANSI, utf8 nd unicode

Sir please Help me.

Thanks in advance.

my code is.........
---------------------------------
C#
using System;
using System.Data;
using System.IO;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Bibliometric.BusinessLogicLayer.BibliometricBO;

public partial class Publication : System.Web.UI.Page
{
    #region To Declare variable and Object
    PublicationBO objPublication = new PublicationBO();
    CitationBO objCitation = new CitationBO();
    ReportBO objReport = new ReportBO();
    #endregion

    #region Page Load Event
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack)
        //{
        //    ddlCustomer.Items.Insert(0, "--Select--");
        //}
    }
    #endregion

    #region btnSave event to save publication detail
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string ScientistName = txtScientistName.Text.Trim();
            string ScientistCitedName = txtCusCitationName.Text.Trim();
            string OPFileName = txtOPFilename.Text.Trim();
            string AuthorName = txtAuthorName.Text.Trim().ToUpper();
            string Year = txtYear.Text.Trim();
            string JournalAbbr1 = txtJournal.Text.Trim().ToUpper();
            string JournalAbbr = JournalAbbr1.Substring(0, JournalAbbr1.IndexOf('(')).Trim();
            string Volume = txtVolume.Text.Trim();
            string BPage = txtPagefrom.Text.Trim();
            string IFYear = txtIFYear.Text.Trim();
            if (txtUploadFileName.HasFile)
            {
                HttpPostedFile file = txtUploadFileName.PostedFile;
                string filepath = file.FileName;
                if (filepath != "")
                {
                    string ext = filepath.Substring(filepath.LastIndexOf('.') + 1, 3);
                    if (filepath.Substring(filepath.LastIndexOf('.') + 1, 3).ToString().ToUpper() != "TXT")
                        lblMsg.Text = "File is not in .txt format !!";
                    else
                    {
                        string filename = GetFileName(file);
                        file.SaveAs(Server.MapPath(filename));
                        string path = Server.MapPath(filename);
                        //call method to parse the text file into XML
                        string CitationXML = objCitation.ParseTXTFile(path);

                        //save customer publication detail
                        string UploadFileName = filename;

                        #region Store all control value in viewstate
                        ViewState["AuthorName"] = AuthorName;
                        ViewState["Year"] = Year; ViewState["Journal"] = JournalAbbr; ViewState["Volume"] = Volume;
                        ViewState["BPage"] = BPage;
                        #endregion

                        //call method to check file name
                        string ReturnText = objPublication.CheckFileName(ScientistName, ScientistCitedName, UploadFileName, OPFileName);
                        if (ReturnText.Contains("upload"))
                        {
                            lblMsg.Text = ReturnText;
                        }
                        else if (ReturnText.Contains("output"))
                        {
                            lblMsg.Text = ReturnText;
                        }
                        else
                        {
                            int ReturnValue = 0;
                            if (btnSave.Text == "Save")
                            {
                                ReturnValue = objPublication.SavePublicationDetail(CitationXML, ScientistName, ScientistCitedName, UploadFileName, OPFileName, AuthorName, Year, JournalAbbr, Volume, BPage,IFYear);
                                if (ReturnValue > 0)
                                {
                                    ViewState["PublicationID"] = ReturnValue;
                                    lblMsg.Text = "Your record saved successfully!";
                                    txtAuthorName.Text = ""; txtYear.Text = ""; txtJournal.Text = ""; txtVolume.Text = ""; txtPagefrom.Text = "";
                                    btnBack.Visible = true;
                                    divReport.Attributes.Add("style", "visibility:visible");
                                }
                            }
                            if (btnSave.Text == "Update")
                            {
                                int PublicationID = Convert.ToInt32(ViewState["PublicationID"].ToString());
                                ReturnValue = objPublication.UpdatePublicationDetail(PublicationID, CitationXML, ScientistName, ScientistCitedName, UploadFileName, OPFileName, AuthorName, Year, JournalAbbr, Volume, BPage,IFYear);
                                if (ReturnValue > 0)
                                {
                                    ViewState["PublicationID"] = ReturnValue;
                                    lblMsg.Text = "Your record updated successfully!";
                                    txtAuthorName.Text = ""; txtYear.Text = ""; txtJournal.Text = ""; txtVolume.Text = ""; txtPagefrom.Text = "";
                                    btnBack.Visible = true; btnSave.Text = "Save";
                                    divReport.Attributes.Add("style", "visibility:visible");
                                }
                            }
                            ViewState["PublicationID"] = ReturnValue.ToString();
                        }
                        File.Delete(path);///Delete file
                    }
                }
            }
            else
            {
                //save customer publication detail               

                #region Store all control value in viewstate
                ViewState["AuthorName"] = AuthorName;
                ViewState["Year"] = Year; ViewState["Journal"] = JournalAbbr; ViewState["Volume"] = Volume;
                ViewState["BPage"] = BPage;
                #endregion
                //call method to check file name
                string ReturnText = objPublication.CheckFileName(ScientistName, ScientistCitedName, "uploadfilename.qmp", OPFileName);
                if (ReturnText.Contains("upload"))
                {
                    lblMsg.Text = ReturnText;
                }
                else if (ReturnText.Contains("output"))
                {
                    lblMsg.Text = ReturnText;
                }
                else
                {
                    int ReturnValue = 0;
                    if (btnSave.Text == "Save")
                    {
                        ReturnValue = objPublication.SavePublicationDetailWithoutCitation(ScientistName, ScientistCitedName, OPFileName, AuthorName, Year, JournalAbbr, Volume, BPage,IFYear);
                        if (ReturnValue > 0)
                        {
                            ViewState["PublicationID"] = ReturnValue;
                            lblMsg.Text = "Your record saved successfully!";
                            txtAuthorName.Text = ""; txtYear.Text = ""; txtJournal.Text = ""; txtVolume.Text = ""; txtPagefrom.Text = "";
                            btnBack.Visible = true;
                            divReport.Attributes.Add("style", "visibility:visible");
                        }
                    }
                    if (btnSave.Text == "Update")
                    {
                        int PublicationID = Convert.ToInt32(ViewState["PublicationID"].ToString());
                        ReturnValue = objPublication.UpdatePublicationDetailWithoutCitation(PublicationID, ScientistName, ScientistCitedName, OPFileName, AuthorName, Year, JournalAbbr, Volume, BPage,IFYear);
                        if (ReturnValue > 0)
                        {
                            ViewState["PublicationID"] = ReturnValue;
                            lblMsg.Text = "Your record updated successfully!";
                            txtAuthorName.Text = ""; txtYear.Text = ""; txtJournal.Text = ""; txtVolume.Text = ""; txtPagefrom.Text = "";
                            btnBack.Visible = true; btnSave.Text = "Save";
                            divReport.Attributes.Add("style", "visibility:visible");
                        }
                    }
                    ViewState["PublicationID"] = ReturnValue.ToString();
                }
            }
        }
        catch { }
    }
    #endregion
    
    #region SelectedIndexChanged event og ddlCustomerType
    //protected void ddlCustomerType_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (ddlCustomerType.SelectedItem.ToString() != "--Select--")
    //    {
    //        //To bind the ddlCustomer
    //        objPublication.GetCustomer(Convert.ToInt16(ddlCustomerType.SelectedValue));
    //        ddlCustomer.DataTextField = "CustomerName";
    //        ddlCustomer.DataValueField = "CustomerID";
    //        ddlCustomer.DataSource = objPublication.CustomerDS;
    //        ddlCustomer.DataBind();
    //        ddlCustomer.Items.Insert(0, "--Select--");
    //    }
    //}
    #endregion

    #region btnBack event for showing previous record for update
    protected void btnBack_Click(object sender, EventArgs e)
    {
        txtAuthorName.Text = ViewState["AuthorName"].ToString(); txtYear.Text = ViewState["Year"].ToString(); txtJournal.Text = ViewState["Journal"].ToString();
        txtVolume.Text = ViewState["Volume"].ToString(); txtPagefrom.Text = ViewState["BPage"].ToString();
        btnSave.Text = "Update"; lblMsg.Text = "";
    }
    #endregion

    #region Generate word file report
    protected void ibtnGenerateWord_Click(object sender, ImageClickEventArgs e)
    {
        txtScientistName.Text = ""; txtCusCitationName.Text = ""; txtOPFilename.Text = "";
        objReport.GenerateTable(tblReport, tblReport1, tblReport2, tblReport3, Convert.ToInt16(ViewState["PublicationID"].ToString()), txtScientistName.Text.Trim());
        Response.Clear();
        Response.Buffer = true;
        string filedoc = txtOPFilename.Text.Trim();
        Response.AddHeader("content-disposition", "attachment;filename=" + filedoc + ".doc");
        Response.ContentEncoding = System.Text.Encoding.Default;
        Response.ContentType = "application/msword";
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        this.pnlReport.RenderControl(oHtmlTextWriter);
        Response.Output.Write(oStringWriter.ToString());
        Response.Flush();
        Response.End();
    }
    #endregion

    #region method to find file name
    private string GetFileName(HttpPostedFile file)
    {
        int i = 0, j = 0;
        string filename;

        filename = file.FileName;
        do
        {
            i = filename.IndexOf(@"\", j + 1);
            if (i >= 0) j = i;
        } while (i >= 0);
        filename = filename.Substring(j + 1, filename.Length - j - 1);

        return filename;
    }
#endregion
}
Posted
Updated 11-Jun-12 21:26pm
v2
Comments
manu027 12-Jun-12 7:04am    
sir please any body give the ans of my question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900