예제 #1
0
    /// <summary>
    /// Modified By Anjali DT:14-10-2016
    /// To save attached files to DB.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="file"></param>
    protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
    {
        try
        {
            dtattachment = (DataTable)Session["Attachment"];


            Byte[] fileBytes = file.GetContents();
            string sPath     = Server.MapPath("\\" + System.Configuration.ConfigurationManager.AppSettings["APP_NAME"].ToString() + "\\uploads\\Technical");
            string sPath1    = Server.MapPath("\\" + System.Configuration.ConfigurationManager.AppSettings["APP_NAME"].ToString() + "\\uploads\\Inspection");
            Guid   GUID      = Guid.NewGuid();
            string _fileName = "";

            string Flag_Attach = GUID.ToString() + Path.GetExtension(file.FileName);


            int Vessel_ID   = Convert.ToInt32(Request.QueryString["VesselID"].ToString()); /* Here it should be received after inserting data TEC_WORKLIST_MAIN*/
            int Worklist_ID = Convert.ToInt32(Session["WID"]);                             /* Here it should be received after inserting data TEC_WORKLIST_MAIN*/
            int Office_ID   = Convert.ToInt32(Session["OID"]);                             /* Here it should be received after inserting data TEC_WORKLIST_MAIN*/

            int FileID = objInsp.Insert_Worklist_Attachment(Vessel_ID, Worklist_ID, Office_ID, UDFLib.Remove_Special_Characters(Path.GetFileName(file.FileName)), Flag_Attach,
                                                            file.FileSize, UDFLib.ConvertToInteger(Session["USERID"]));

            _fileName = "TEC_" + Vessel_ID + "_" + Worklist_ID + "_" + Office_ID + "_" + "O" + "_" + FileID.ToString() + "_" + Flag_Attach;

            if (FileID > 0)
            {
                int Ret = objInsp.Insert_ActivityObject(Vessel_ID, Worklist_ID, Office_ID, UDFLib.Remove_Special_Characters(Path.GetFileName(file.FileName)), /* filattachPath, */ _fileName,
                                                        UDFLib.ConvertToInteger(Session["USERID"]));

                string FullFilename = Path.Combine(sPath, _fileName);

                //Save attached file to folder
                FileStream fileStream = new FileStream(FullFilename, FileMode.Create, FileAccess.ReadWrite);
                fileStream.Write(fileBytes, 0, fileBytes.Length);
                fileStream.Close();


                File.Copy(FullFilename, Path.Combine(sPath1, _fileName));

                Load_Attachments(Vessel_ID, Worklist_ID, Office_ID, UDFLib.ConvertToInteger(Session["USERID"]));

                string jsPopClose = " hideModal('dvPopupAddAttachment');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "jsPopClose", jsPopClose, true);
            }
            else
            {
                string jsPopAlert = " alert('File Already exists.');";
                ScriptManager.RegisterStartupScript(AjaxFileUpload1, AjaxFileUpload1.GetType(), "jsPopAlert", jsPopAlert, true);
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
        }
    }