Example #1
0
        private bool UploadDocument()
        {
            try
            {
                // login to ftp server\

                //strRemoteUrl="http://www.compassnav.com/";
                //strRemoteUrl=Info.getInstance().WebsiteName +@"/";

                //zaeem: Hard coded to run on Vista System
                //strRemoteUrl="http://216.117.130.240:5216"+@"/";
                //strRemoteUrl="http://soerwa.hopto.org/Compassnav"+@"/";
                strRemoteUrl="http://vista/Compassnav"+@"/";

                //FtpClient ftp = new FtpClient(m_serverIP,m_username,m_password);
                //FtpClient ftp = new FtpClient("soerwa.hopto.org","zaeem","zaeem");
                FtpClient ftp = new FtpClient("vista","Ahmed","three");

                ftp.OnStatusUpdateFunction = new WebMeeting.FTP.FtpClient.OnStatusUpdate(FtpUploadStatus);
                try
                {
                    if(OnStatusUpdateFunction !=null)
                        OnStatusUpdateFunction(LOGGING_MSG);//"Unable to upload files to WebServer. " + ee.Message);

                    ftp.Login();
                }
                catch(Exception exp)
                {

                    WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>341",exp,"Unable to Logon to server.",true);
                    if(OnStatusUpdateFunction !=null)
                        OnStatusUpdateFunction("Unable to Logon to server.");
                    return false;
                }

                try
                {

                    ftp.ChangeDir("WebMeeting");
                }
                catch(Exception exp)
                {
                    WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>355",exp,null,false);
                    ftp.MakeDir("WebMeeting");
                    ftp.ChangeDir("WebMeeting");
                }
                strRemoteUrl+="WebMeeting/";

                try
                {
                    ftp.ChangeDir("Uploads");
                }
                catch(Exception exp)
                {
                    WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>367",exp,null,false);
                    ftp.MakeDir("Uploads");
                    ftp.ChangeDir("Uploads");
                }
                strRemoteUrl+="Uploads/";
                try
                {
                    ftp.MakeDir(m_meetingID);//.GetFileList();
                    strRemoteUrl+=(m_meetingID.ToString()+"/");
                }
                catch(Exception exp)
                {
                    WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>379",exp,null,false);
                    // it already exists
                }

                if(OnStatusUpdateFunction !=null)
                    OnStatusUpdateFunction(LOGGED_ON_MSG);//"Unable to upload files to WebServer. " + ee.Message);

                ftp.ChangeDir(m_meetingID);

                try
                {
                    ftp.MakeDir(sessionID.ToString());//.GetFileList();
                    strRemoteUrl+=sessionID.ToString()+"/";
                }
                catch(Exception exp)
                {
                    WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>395",exp,null,false);

                    // it already exists
                }
                OnStatusUpdateFunction(UPLOADING_MSG);
                ftp.ChangeDir(sessionID.ToString());
                string documentFolderName = "";
                try
                {

                    if(this.m_DocumentType == DocumentMessageType.typeDocument)
                        documentFolderName = "Documents";
                    else if(this.m_DocumentType == DocumentMessageType.typeExcel)
                        documentFolderName = "WorkBooks";
                    else if(this.m_DocumentType == DocumentMessageType.typePDF)
                        documentFolderName = "PDF";
                    else if(this.m_DocumentType == DocumentMessageType.typePresentation)
                        documentFolderName = "Presentations";

                    ftp.MakeDir(documentFolderName);
                    strRemoteUrl+=documentFolderName;

                }
                catch(Exception exp )
                {
                    WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>419",exp,null,false);

                }

                ftp.ChangeDir(documentFolderName);
                try
                {
                    if(OnStatusUpdateFunction !=null)
                        OnStatusUpdateFunction(COMPRESSING_MSG + Path.GetFileName(m_sharedFilePath));//"Unable to upload files to WebServer. " + ee.Message);

                    string localFile = "";
                    string fileWithoutExt = "";
                    if(m_sharedFilePath.IndexOf("Downloaded", 0, m_sharedFilePath.Length)!=-1)
                    {
                        localFile = m_sharedFilePath;
                    }
                    else
                    {
                        fileWithoutExt = Path.GetFileNameWithoutExtension(m_sharedFilePath);
                        /*
                            if(fileWithoutExt.IndexOf(".") > 0)
                        {
                            MessageBox.Show("==>file with Dot");
                            fileWithoutExt = Path.GetFileNameWithoutExtension(fileWithoutExt );

                            localFile = Application.StartupPath + "\\DocumentSharing\\Uploaded\\" + documentFolderName + "\\"  + fileWithoutExt ;
                            CreateLocalDirectoryStructure(true);
                            if(Directory.Exists(localFile))
                                Directory.Delete(localFile,true);
                            Directory.CreateDirectory(localFile);

                            localFile += "\\" + Path.GetFileName(m_sharedFilePath) ;
                        }
                        else
                        */
                        //{
                        //	MessageBox.Show("==>file with NOOOOO Dot");

                            localFile = Application.StartupPath + "\\DocumentSharing\\Uploaded\\" + documentFolderName + "\\"  + fileWithoutExt ;
                            CreateLocalDirectoryStructure(true);
                            if(Directory.Exists(localFile))
                                Directory.Delete(localFile,true);
                            Directory.CreateDirectory(localFile);

                            localFile += "\\" + Path.GetFileName(m_sharedFilePath) + ".zip";
                        //}

                    }

                    try
                    {

                        ICSharpZip.ZipFile(m_sharedFilePath, localFile);
                        if(OnStatusUpdateFunction !=null)
                            OnStatusUpdateFunction(UPLOADING_MSG + Path.GetFileName(m_sharedFilePath));//"Unable to upload files to WebServer. " + ee.Message);
                    }
                    catch(Exception exp)
                    {
                        WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>474",exp,exp.Message.ToString(),true);

                    }

                    ftp.Upload(localFile);
                    //ftp.Upload(this.m_sharedFilePath);
                    //ftp.UploadDirectory(destFile,true);
                    ftp.Close();
                //	theFile=new FileInfo(localFile);
                //	theFile.Delete();

                    return true;

                }
                catch(Exception exp)
                {
                    WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>490",exp,"Unable to upload files to WebServer. " + exp.Message.ToString(),true);
                    if(OnStatusUpdateFunction !=null)
                        OnStatusUpdateFunction("Unable to upload files to WebServer. " + exp.Message);

                    //ftp.Close();
                    //MessageBox.Show("Couldnt upload " + ee.ToString());
                    //Zaeem//return false;
                    return true;
                }

            }
            catch(Exception exp)
            {
                WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage( "DocumentSharingEx.cs ==>UploadDocument() line==>490",exp,"Unable to upload files to WebServer. " + exp.Message.ToString(),true);
                if(OnStatusUpdateFunction !=null)
                    OnStatusUpdateFunction("Unable to upload files to WebServer. " + exp.Message);

              			 // MessageBox.Show("Couldnt upload " + ee.ToString());
            }
            //return false;
            return true;;
        }