Exemplo n.º 1
0
 public void UpdateUrlTracking(int PortalID, string Url, int ModuleId, int UserID)
 {
     TabType UrlType = Globals.GetURLType(Url);
     if (UrlType == TabType.File && Url.ToLower().StartsWith("fileid=") == false)
     {
         FileController objFiles = new FileController();
         Url = "FileID=" + objFiles.ConvertFilePathToFileId(Url, PortalID);
     }
     UrlTrackingInfo objUrlTracking = GetUrlTracking(PortalID, Url, ModuleId);
     if (objUrlTracking != null)
     {
         if (objUrlTracking.TrackClicks)
         {
             DataProvider.Instance().UpdateUrlTrackingStats(PortalID, Url, ModuleId);
             if (objUrlTracking.LogActivity)
             {
                 if (UserID == -1)
                 {
                     UserID = UserController.GetCurrentUserInfo().UserID;
                 }
                 DataProvider.Instance().AddUrlLog(objUrlTracking.UrlTrackingID, UserID);
             }
         }
     }
 }
 private static string AddFile(int PortalId, Stream inStream, string fileName, string contentType, long length, string folderName, bool closeInputStream, bool clearCache, bool synchronize)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
     string sourceFolderName = Globals.GetSubFolderPath(fileName, PortalId);
     CommonLibrary.Services.FileSystem.FolderInfo folder = objFolderController.GetFolder(PortalId, sourceFolderName, false);
     string sourceFileName = GetFileName(fileName);
     int intFileID;
     string retValue = "";
     retValue += CheckValidFileName(fileName);
     if (!String.IsNullOrEmpty(retValue))
     {
         return retValue;
     }
     string extension = Path.GetExtension(fileName).Replace(".", "");
     if (String.IsNullOrEmpty(contentType))
     {
         contentType = GetContentType(extension);
     }
     intFileID = objFileController.AddFile(PortalId, sourceFileName, extension, length, Null.NullInteger, Null.NullInteger, contentType, folderName, folder.FolderID, clearCache);
     if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem || synchronize == false)
     {
         WriteStream(intFileID, inStream, fileName, folder.StorageLocation, closeInputStream);
     }
     retValue += UpdateFileData(intFileID, folder.FolderID, PortalId, sourceFileName, extension, contentType, length, folderName);
     if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem)
     {
         DeleteFile(fileName);
     }
     if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem)
     {
         if (!fileName.EndsWith(".template"))
         {
             DeleteFile(fileName + Globals.glbProtectedExtension);
         }
     }
     return retValue;
 }
 public int ConvertFilePathToFileId(string FilePath, int PortalID)
 {
     string FileName = "";
     string FolderName = "";
     int FileId = -1;
     if (!String.IsNullOrEmpty(FilePath))
     {
         FileName = FilePath.Substring(FilePath.LastIndexOf("/") + 1);
         FolderName = FilePath.Replace(FileName, "");
     }
     FileController objFiles = new FileController();
     FolderController objFolders = new FolderController();
     FolderInfo objFolder = objFolders.GetFolder(PortalID, FolderName, false);
     if (objFolder != null)
     {
         FileInfo objFile = objFiles.GetFile(FileName, PortalID, objFolder.FolderID);
         if (objFile != null)
         {
             FileId = objFile.FileId;
         }
     }
     return FileId;
 }
 private static void WriteStream(int fileId, Stream inStream, string fileName, int storageLocation, bool closeInputStream)
 {
     CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
     byte[] arrData = new byte[2048];
     Stream outStream = null;
     try
     {
         switch (storageLocation)
         {
             case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure:
                 objFileController.ClearFileContent(fileId);
                 outStream = new MemoryStream();
                 break;
             case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem:
                 if (File.Exists(fileName + Globals.glbProtectedExtension) == true)
                 {
                     File.Delete(fileName + Globals.glbProtectedExtension);
                 }
                 outStream = new FileStream(fileName + Globals.glbProtectedExtension, FileMode.Create);
                 break;
             case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem:
                 if (File.Exists(fileName) == true)
                 {
                     File.Delete(fileName);
                 }
                 outStream = new FileStream(fileName, FileMode.Create);
                 break;
         }
     }
     catch (Exception ex)
     {
         if (inStream != null && closeInputStream)
         {
             inStream.Close();
             inStream.Dispose();
         }
         if (outStream != null)
         {
             outStream.Close();
             outStream.Dispose();
         }
         throw ex;
     }
     try
     {
         int intLength;
         intLength = inStream.Read(arrData, 0, arrData.Length);
         while (intLength > 0)
         {
             outStream.Write(arrData, 0, intLength);
             intLength = inStream.Read(arrData, 0, arrData.Length);
         }
         if (storageLocation == (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure)
         {
             outStream.Seek(0, SeekOrigin.Begin);
             objFileController.UpdateFileContent(fileId, outStream);
         }
     }
     catch (Exception ex)
     {
         Exceptions.LogException(ex);
     }
     finally
     {
         if (inStream != null == false && closeInputStream)
         {
             inStream.Close();
             inStream.Dispose();
         }
         if (outStream != null)
         {
             outStream.Close();
             outStream.Dispose();
         }
     }
 }
 private static string UpdateFileData(int fileID, int folderID, int PortalId, string fileName, string extension, string contentType, long length, string folderName)
 {
     string retvalue = "";
     try
     {
         CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
         int imageWidth = 0;
         int imageHeight = 0;
         if ((Globals.glbImageFileTypes + ",").IndexOf(extension.ToLower() + ",") > -1)
         {
             System.Drawing.Image imgImage = null;
             Stream imageStream = null;
             try
             {
                 CommonLibrary.Services.FileSystem.FileInfo objFile = objFileController.GetFileById(fileID, PortalId);
                 imageStream = GetFileStream(objFile);
                 imgImage = System.Drawing.Image.FromStream(imageStream);
                 imageHeight = imgImage.Height;
                 imageWidth = imgImage.Width;
             }
             catch
             {
                 contentType = "application/octet-stream";
             }
             finally
             {
                 if (imgImage != null)
                 {
                     imgImage.Dispose();
                 }
                 if (imageStream != null)
                 {
                     imageStream.Close();
                     imageStream.Dispose();
                 }
                 objFileController.UpdateFile(fileID, fileName, extension, length, imageWidth, imageHeight, contentType, folderName, folderID);
             }
         }
     }
     catch (Exception ex)
     {
         retvalue = ex.Message;
     }
     return retvalue;
 }
 private static string UpdateFile(string strSourceFile, string strDestFile, int PortalId, bool isCopy, bool isNew, bool ClearCache)
 {
     string retValue = "";
     retValue += CheckValidFileName(strSourceFile) + " ";
     retValue += CheckValidFileName(strDestFile);
     if (retValue.Length > 1)
     {
         return retValue;
     }
     retValue = "";
     Stream sourceStream = null;
     try
     {
         CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
         CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
         string sourceFolderName = Globals.GetSubFolderPath(strSourceFile, PortalId);
         string sourceFileName = GetFileName(strSourceFile);
         CommonLibrary.Services.FileSystem.FolderInfo sourceFolder = objFolderController.GetFolder(PortalId, sourceFolderName, false);
         string destFileName = GetFileName(strDestFile);
         string destFolderName = Globals.GetSubFolderPath(strDestFile, PortalId);
         CommonLibrary.Services.FileSystem.FileInfo file;
         if (sourceFolder != null)
         {
             file = objFileController.GetFile(sourceFileName, PortalId, sourceFolder.FolderID);
             if (file != null)
             {
                 sourceStream = (Stream)GetFileStream(file);
                 if (isCopy)
                 {
                     AddFile(PortalId, sourceStream, strDestFile, "", file.Size, destFolderName, true, ClearCache);
                 }
                 else
                 {
                     CommonLibrary.Services.FileSystem.FolderInfo destinationFolder = objFolderController.GetFolder(PortalId, destFolderName, false);
                     if (destinationFolder != null)
                     {
                         objFileController.UpdateFile(file.FileId, destFileName, file.Extension, file.Size, file.Width, file.Height, file.ContentType, destFolderName, destinationFolder.FolderID);
                         WriteStream(file.FileId, sourceStream, strDestFile, destinationFolder.StorageLocation, true);
                         if (sourceFolder.StorageLocation == (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem)
                         {
                             DeleteFile(strSourceFile);
                         }
                         if (sourceFolder.StorageLocation == (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem)
                         {
                             DeleteFile(strSourceFile + Globals.glbProtectedExtension);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         retValue = ex.Message;
     }
     finally
     {
         if (sourceStream != null)
         {
             sourceStream.Close();
             sourceStream.Dispose();
         }
     }
     return retValue;
 }
 private static void RemoveOrphanedFile(CommonLibrary.Services.FileSystem.FileInfo objFile, int PortalId)
 {
     CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
     string strFile = "";
     switch (objFile.StorageLocation)
     {
         case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem:
             strFile = objFile.PhysicalPath;
             break;
         case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem:
             strFile = objFile.PhysicalPath + Globals.glbProtectedExtension;
             break;
     }
     if (!String.IsNullOrEmpty(strFile))
     {
         if (!File.Exists(strFile))
         {
             objFileController.DeleteFile(PortalId, objFile.FileName, objFile.FolderId, true);
         }
     }
 }
 public static bool DownloadFile(int PortalId, int FileId, bool ClientCache, bool ForceDownload)
 {
     bool blnDownload = false;
     CommonLibrary.Services.FileSystem.FileController objFiles = new CommonLibrary.Services.FileSystem.FileController();
     CommonLibrary.Services.FileSystem.FileInfo objFile = objFiles.GetFileById(FileId, PortalId);
     if (objFile != null)
     {
         string filename = objFile.FileName;
         if (HttpContext.Current.Request.UserAgent.IndexOf("; MSIE ") > 0)
         {
             filename = HttpUtility.UrlEncode(filename);
         }
         CommonLibrary.Services.FileSystem.FolderController objFolders = new CommonLibrary.Services.FileSystem.FolderController();
         CommonLibrary.Services.FileSystem.FolderInfo objFolder = objFolders.GetFolder(PortalId, objFile.Folder, false);
         if (FolderPermissionController.CanViewFolder(objFolder))
         {
             bool blnFileExists = true;
             if (Host.EnableFileAutoSync)
             {
                 string strFile = "";
                 switch (objFile.StorageLocation)
                 {
                     case (int)FolderController.StorageLocationTypes.InsecureFileSystem:
                         strFile = objFile.PhysicalPath;
                         break;
                     case (int)FolderController.StorageLocationTypes.SecureFileSystem:
                         strFile = objFile.PhysicalPath + Globals.glbProtectedExtension;
                         break;
                 }
                 if (!String.IsNullOrEmpty(strFile))
                 {
                     System.IO.FileInfo objFileInfo = new System.IO.FileInfo(strFile);
                     if (objFileInfo.Exists)
                     {
                         if (objFile.Size != objFileInfo.Length)
                         {
                             objFile.Size = Convert.ToInt32(objFileInfo.Length);
                             UpdateFileData(FileId, objFile.FolderId, PortalId, objFile.FileName, objFile.Extension, GetContentType(objFile.Extension), objFileInfo.Length, objFile.Folder);
                         }
                     }
                     else
                     {
                         RemoveOrphanedFile(objFile, PortalId);
                         blnFileExists = false;
                     }
                 }
             }
             if (blnFileExists)
             {
                 int scriptTimeOut = HttpContext.Current.Server.ScriptTimeout;
                 HttpContext.Current.Server.ScriptTimeout = int.MaxValue;
                 HttpResponse objResponse = HttpContext.Current.Response;
                 objResponse.ClearContent();
                 objResponse.ClearHeaders();
                 if (ForceDownload)
                 {
                     objResponse.AppendHeader("content-disposition", "attachment; filename=\"" + filename + "\"");
                 }
                 else
                 {
                     objResponse.AppendHeader("content-disposition", "inline; filename=\"" + filename + "\"");
                 }
                 objResponse.AppendHeader("Content-Length", objFile.Size.ToString());
                 objResponse.ContentType = GetContentType(objFile.Extension.Replace(".", ""));
                 System.IO.Stream objStream = null;
                 try
                 {
                     objStream = FileSystemUtils.GetFileStream(objFile);
                     WriteStream(objResponse, objStream);
                 }
                 catch (Exception ex)
                 {
                     objResponse.Write("Error : " + ex.Message);
                 }
                 finally
                 {
                     if (objStream != null)
                     {
                         objStream.Close();
                         objStream.Dispose();
                     }
                 }
                 objResponse.Flush();
                 objResponse.End();
                 HttpContext.Current.Server.ScriptTimeout = scriptTimeOut;
                 blnDownload = true;
             }
         }
     }
     return blnDownload;
 }
 public static string AddFile(string strFile, int PortalId, bool ClearCache, CommonLibrary.Services.FileSystem.FolderInfo folder)
 {
     string retValue = "";
     try
     {
         CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
         System.IO.FileInfo fInfo = new System.IO.FileInfo(strFile);
         string sourceFolderName = Globals.GetSubFolderPath(strFile, PortalId);
         string sourceFileName;
         if (folder.StorageLocation == (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem)
         {
             sourceFileName = GetFileName(strFile);
         }
         else
         {
             sourceFileName = strFile;
         }
         CommonLibrary.Services.FileSystem.FileInfo file = objFileController.GetFile(sourceFileName, PortalId, folder.FolderID);
         if (file == null)
         {
             FileStream fileStrm = null;
             try
             {
                 fileStrm = fInfo.OpenRead();
                 AddFile(PortalId, fileStrm, strFile, "", fInfo.Length, sourceFolderName, true, ClearCache, true);
             }
             finally
             {
                 if (fileStrm != null)
                 {
                     fileStrm.Close();
                     fileStrm.Dispose();
                 }
             }
         }
         else
         {
             if (file.Size != fInfo.Length)
             {
                 string extension = Path.GetExtension(strFile).Replace(".", "");
                 UpdateFileData(file.FileId, folder.FolderID, PortalId, sourceFileName, extension, GetContentType(extension), fInfo.Length, sourceFolderName);
             }
         }
     }
     catch (Exception ex)
     {
         retValue = ex.Message;
     }
     return retValue;
 }
Exemplo n.º 10
0
 public static Stream GetFileStream(CommonLibrary.Services.FileSystem.FileInfo objFile)
 {
     CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
     Stream fileStream = null;
     switch (objFile.StorageLocation)
     {
         case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem:
             fileStream = new FileStream(objFile.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
             break;
         case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem:
             fileStream = new FileStream(objFile.PhysicalPath + Globals.glbProtectedExtension, FileMode.Open, FileAccess.Read, FileShare.Read);
             break;
         case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure:
             fileStream = new MemoryStream(objFileController.GetFileContent(objFile.FileId, objFile.PortalId));
             break;
     }
     return fileStream;
 }
Exemplo n.º 11
0
        public void ProcessRequest(System.Web.HttpContext context)
        {
            PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
            int            TabId           = -1;
            int            ModuleId        = -1;

            try
            {
                if (context.Request.QueryString["tabid"] != null)
                {
                    Int32.TryParse(context.Request.QueryString["tabid"], out TabId);
                }
                if (context.Request.QueryString["mid"] != null)
                {
                    Int32.TryParse(context.Request.QueryString["mid"], out ModuleId);
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                throw new HttpException(404, "Not Found");
            }
            string Language = _portalSettings.DefaultLanguage;

            if (context.Request.QueryString["language"] != null)
            {
                Language = context.Request.QueryString["language"];
            }
            else
            {
                if (context.Request.Cookies["language"] != null)
                {
                    Language = context.Request.Cookies["language"].Value;
                }
            }
            if (Localization.Localization.LocaleIsEnabled(Language))
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(Language);
                Localization.Localization.SetLanguage(Language);
            }
            string URL              = "";
            bool   blnClientCache   = true;
            bool   blnForceDownload = false;

            if (context.Request.QueryString["fileticket"] != null)
            {
                URL = "FileID=" + UrlUtils.DecryptParameter(context.Request.QueryString["fileticket"]);
            }
            if (context.Request.QueryString["userticket"] != null)
            {
                URL = "UserId=" + UrlUtils.DecryptParameter(context.Request.QueryString["userticket"]);
            }
            if (context.Request.QueryString["link"] != null)
            {
                URL = context.Request.QueryString["link"];
                if (URL.ToLowerInvariant().StartsWith("fileid="))
                {
                    URL = "";
                }
            }
            if (!String.IsNullOrEmpty(URL))
            {
                UrlController objUrls = new UrlController();
                objUrls.UpdateUrlTracking(_portalSettings.PortalId, URL, ModuleId, -1);
                TabType UrlType = Globals.GetURLType(URL);
                if (UrlType != TabType.File)
                {
                    URL = Common.Globals.LinkClick(URL, TabId, ModuleId, false);
                }
                if (UrlType == TabType.File && URL.ToLowerInvariant().StartsWith("fileid=") == false)
                {
                    FileController objFiles = new FileController();
                    URL = "FileID=" + objFiles.ConvertFilePathToFileId(URL, _portalSettings.PortalId);
                }
                if (context.Request.QueryString["clientcache"] != null)
                {
                    blnClientCache = bool.Parse(context.Request.QueryString["clientcache"]);
                }
                if ((context.Request.QueryString["forcedownload"] != null) || (context.Request.QueryString["contenttype"] != null))
                {
                    blnForceDownload = bool.Parse(context.Request.QueryString["forcedownload"]);
                }
                context.Response.Clear();
                try
                {
                    switch (UrlType)
                    {
                    case TabType.File:
                        if (TabId == Null.NullInteger)
                        {
                            if (!FileSystemUtils.DownloadFile(_portalSettings.PortalId, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload))
                            {
                                throw new HttpException(404, "Not Found");
                            }
                        }
                        else
                        {
                            if (!FileSystemUtils.DownloadFile(_portalSettings, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload))
                            {
                                throw new HttpException(404, "Not Found");
                            }
                        }
                        break;

                    case TabType.Url:
                        if (objUrls.GetUrl(_portalSettings.PortalId, URL) != null)
                        {
                            context.Response.Redirect(URL, true);
                        }
                        break;

                    default:
                        context.Response.Redirect(URL, true);
                        break;
                    }
                }
                catch (ThreadAbortException ex)
                {
                    ex.ToString();
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    throw new HttpException(404, "Not Found");
                }
            }
            else
            {
                throw new HttpException(404, "Not Found");
            }
        }
Exemplo n.º 12
0
 public static string ImportFile(int PortalId, string url)
 {
     string strUrl = url;
     if (GetURLType(url) == TabType.File)
     {
         FileController objFileController = new FileController();
         int fileId = objFileController.ConvertFilePathToFileId(url, PortalId);
         if (fileId >= 0)
         {
             strUrl = "FileID=" + fileId.ToString();
         }
     }
     return strUrl;
 }
Exemplo n.º 13
0
 public static ArrayList GetFileList(int PortalId, string strExtensions, bool NoneSpecified, string Folder, bool includeHidden)
 {
     ArrayList arrFileList = new ArrayList();
     if (NoneSpecified)
     {
         arrFileList.Add(new FileItem("", "<" + Localization.GetString("None_Specified") + ">"));
     }
     string portalRoot;
     if (PortalId == Null.NullInteger)
     {
         portalRoot = HostMapPath;
     }
     else
     {
         PortalController objPortals = new PortalController();
         PortalInfo objPortal = objPortals.GetPortal(PortalId);
         portalRoot = objPortal.HomeDirectoryMapPath;
     }
     FolderInfo objFolder = FileSystemUtils.GetFolder(PortalId, Folder);
     if (objFolder != null)
     {
         FileController objFiles = new FileController();
         IDataReader dr = null;
         try
         {
             dr = objFiles.GetFiles(PortalId, objFolder.FolderID);
             while (dr.Read())
             {
                 if (FilenameMatchesExtensions(dr["FileName"].ToString(), strExtensions))
                 {
                     string filePath = (portalRoot + dr["Folder"].ToString() + dr["fileName"].ToString()).Replace("/", "\\");
                     int StorageLocation = 0;
                     if (dr["StorageLocation"] != null)
                     {
                         StorageLocation = Convert.ToInt32(dr["StorageLocation"]);
                         switch (StorageLocation)
                         {
                             case 1:
                                 filePath = filePath + glbProtectedExtension;
                                 break;
                             case 2:
                                 break;
                             default:
                                 break;
                         }
                     }
                     if (StorageLocation != 2)
                     {
                         if (File.Exists(filePath))
                         {
                             if (includeHidden)
                             {
                                 arrFileList.Add(new FileItem(dr["FileID"].ToString(), dr["FileName"].ToString()));
                             }
                             else
                             {
                                 System.IO.FileAttributes attributes = File.GetAttributes(filePath);
                                 if ((attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                                 {
                                     arrFileList.Add(new FileItem(dr["FileID"].ToString(), dr["FileName"].ToString()));
                                 }
                             }
                         }
                     }
                     else
                     {
                         arrFileList.Add(new FileItem(dr["FileID"].ToString(), dr["FileName"].ToString()));
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Exceptions.LogException(ex);
         }
         finally
         {
             CBO.CloseDataReader(dr, true);
         }
     }
     return arrFileList;
 }
Exemplo n.º 14
0
 public static string ImportUrl(int ModuleId, string url)
 {
     string strUrl = url;
     TabType urlType = GetURLType(url);
     int intId = -1;
     PortalSettings portalSettings = GetPortalSettings();
     switch (urlType)
     {
         case TabType.File:
             if (Int32.TryParse(url.Replace("FileID=", ""), out intId))
             {
                 FileController objFileController = new FileController();
                 CommonLibrary.Services.FileSystem.FileInfo objFile = objFileController.GetFileById(intId, portalSettings.PortalId);
                 if (objFile == null)
                 {
                     strUrl = "";
                 }
             }
             else
             {
                 strUrl = "";
             }
             break;
         case TabType.Member:
             if (Int32.TryParse(url.Replace("UserID=", ""), out intId))
             {
                 if (UserController.GetUserById(portalSettings.PortalId, intId) == null)
                 {
                     strUrl = "";
                 }
             }
             else
             {
                 strUrl = "";
             }
             break;
         case TabType.Tab:
             if (Int32.TryParse(url, out intId))
             {
                 TabController objTabController = new TabController();
                 if (objTabController.GetTab(intId, portalSettings.PortalId, false) == null)
                 {
                     strUrl = "";
                 }
             }
             else
             {
                 strUrl = "";
             }
             break;
     }
     return strUrl;
 }
Exemplo n.º 15
0
 public static ArrayList GetFilesByFolder(int PortalId, int folderId)
 {
     CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
     return CBO.FillCollection(objFileController.GetFiles(PortalId, folderId), typeof(CommonLibrary.Services.FileSystem.FileInfo));
 }
Exemplo n.º 16
0
 public static void AddFile(string FileName, int PortalId, string Folder, string HomeDirectoryMapPath, string contentType)
 {
     string strFile = HomeDirectoryMapPath + Folder + FileName;
     CommonLibrary.Services.FileSystem.FileController objFiles = new CommonLibrary.Services.FileSystem.FileController();
     System.IO.FileInfo finfo = new System.IO.FileInfo(strFile);
     CommonLibrary.Services.FileSystem.FolderController objFolders = new CommonLibrary.Services.FileSystem.FolderController();
     CommonLibrary.Services.FileSystem.FolderInfo objFolder = objFolders.GetFolder(PortalId, Folder, false);
     CommonLibrary.Services.FileSystem.FileInfo objFile;
     objFile = objFiles.GetFile(FileName, PortalId, objFolder.FolderID);
     if (objFile == null)
     {
         objFiles.AddFile(PortalId, FileName, finfo.Extension, finfo.Length, 0, 0, contentType, "", objFolder.FolderID, true);
     }
     else
     {
         objFiles.UpdateFile(objFile.FileId, objFile.FileName, finfo.Extension, finfo.Length, 0, 0, contentType, "", objFolder.FolderID);
     }
 }
Exemplo n.º 17
0
 public static string UnzipFile(string fileName, string DestFolder, PortalSettings settings)
 {
     ZipInputStream objZipInputStream = null;
     string strMessage = "";
     try
     {
         int FolderPortalId = GetFolderPortalId(settings);
         bool isHost = settings.ActiveTab.ParentId == settings.SuperTabId;
         PortalController objPortalController = new PortalController();
         CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
         CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
         string sourceFolderName = Globals.GetSubFolderPath(fileName, FolderPortalId);
         string sourceFileName = GetFileName(fileName);
         CommonLibrary.Services.FileSystem.FolderInfo folder = objFolderController.GetFolder(FolderPortalId, sourceFolderName, false);
         CommonLibrary.Services.FileSystem.FileInfo file = objFileController.GetFile(sourceFileName, FolderPortalId, folder.FolderID);
         int storageLocation = folder.StorageLocation;
         ZipEntry objZipEntry;
         string strFileName = "";
         string strExtension;
         try
         {
             objZipInputStream = new ZipInputStream(GetFileStream(file));
         }
         catch (Exception ex)
         {
             return ex.Message;
         }
         ArrayList sortedFolders = new ArrayList();
         objZipEntry = objZipInputStream.GetNextEntry();
         while (objZipEntry != null)
         {
             if (objZipEntry.IsDirectory)
             {
                 try
                 {
                     sortedFolders.Add(objZipEntry.Name.ToString());
                 }
                 catch (Exception ex)
                 {
                     objZipInputStream.Close();
                     return ex.Message;
                 }
             }
             objZipEntry = objZipInputStream.GetNextEntry();
         }
         sortedFolders.Sort();
         foreach (string s in sortedFolders)
         {
             try
             {
                 AddFolder(settings, DestFolder, s.ToString(), storageLocation);
             }
             catch (Exception ex)
             {
                 return ex.Message;
             }
         }
         objZipInputStream = new ZipInputStream(GetFileStream(file));
         objZipEntry = objZipInputStream.GetNextEntry();
         while (objZipEntry != null)
         {
             if (!objZipEntry.IsDirectory)
             {
                 if (objPortalController.HasSpaceAvailable(FolderPortalId, objZipEntry.Size))
                 {
                     strFileName = Path.GetFileName(objZipEntry.Name);
                     if (!String.IsNullOrEmpty(strFileName))
                     {
                         strExtension = Path.GetExtension(strFileName).Replace(".", "");
                         if (("," + Host.FileExtensions.ToLower()).IndexOf("," + strExtension.ToLower()) != 0 || isHost)
                         {
                             try
                             {
                                 string folderPath = System.IO.Path.GetDirectoryName(DestFolder + objZipEntry.Name.Replace("/", "\\"));
                                 DirectoryInfo Dinfo = new DirectoryInfo(folderPath);
                                 if (!Dinfo.Exists)
                                 {
                                     AddFolder(settings, DestFolder, objZipEntry.Name.Substring(0, objZipEntry.Name.Replace("/", "\\").LastIndexOf("\\")));
                                 }
                                 string zipEntryFileName = DestFolder + objZipEntry.Name.Replace("/", "\\");
                                 strMessage += AddFile(FolderPortalId, objZipInputStream, zipEntryFileName, "", objZipEntry.Size, Globals.GetSubFolderPath(zipEntryFileName, settings.PortalId), false, false);
                             }
                             catch (Exception ex)
                             {
                                 if (objZipInputStream != null)
                                 {
                                     objZipInputStream.Close();
                                 }
                                 return ex.Message;
                             }
                         }
                         else
                         {
                             strMessage += "<br>" + string.Format(Localization.GetString("RestrictedFileType"), strFileName, Host.FileExtensions.Replace(",", ", *."));
                         }
                     }
                 }
                 else
                 {
                     strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFileName);
                 }
             }
             objZipEntry = objZipInputStream.GetNextEntry();
         }
     }
     finally
     {
         if (objZipInputStream != null)
         {
             objZipInputStream.Close();
             objZipInputStream.Dispose();
         }
     }
     return strMessage;
 }
Exemplo n.º 18
0
 public static string DeleteFile(string strSourceFile, PortalSettings settings, bool ClearCache)
 {
     string retValue = "";
     int PortalId = GetFolderPortalId(settings);
     string folderName = Globals.GetSubFolderPath(strSourceFile, PortalId);
     string fileName = GetFileName(strSourceFile);
     CommonLibrary.Services.FileSystem.FolderController objFolders = new CommonLibrary.Services.FileSystem.FolderController();
     CommonLibrary.Services.FileSystem.FolderInfo objFolder = objFolders.GetFolder(PortalId, folderName, false);
     if (FolderPermissionController.CanAdminFolder(objFolder))
     {
         try
         {
             DeleteFile(strSourceFile);
             DeleteFile(strSourceFile + Globals.glbProtectedExtension);
             CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
             objFileController.DeleteFile(PortalId, fileName, objFolder.FolderID, ClearCache);
         }
         catch (IOException ioEx)
         {
             retValue += "<br>" + string.Format(Localization.GetString("FileInUse"), strSourceFile);
             ioEx.ToString();
         }
         catch (Exception ex)
         {
             retValue = ex.Message;
         }
     }
     else
     {
         retValue += "<br>" + string.Format(Localization.GetString("InsufficientFolderPermission"), folderName);
     }
     return retValue;
 }
Exemplo n.º 19
0
 private static void RemoveOrphanedFiles(CommonLibrary.Services.FileSystem.FolderInfo folder, int PortalId)
 {
     CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
     if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure)
     {
         foreach (CommonLibrary.Services.FileSystem.FileInfo objFile in GetFilesByFolder(PortalId, folder.FolderID))
         {
             RemoveOrphanedFile(objFile, PortalId);
         }
     }
 }
 public void ProcessRequest(System.Web.HttpContext context)
 {
     PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
     int TabId = -1;
     int ModuleId = -1;
     try
     {
         if (context.Request.QueryString["tabid"] != null)
         {
             Int32.TryParse(context.Request.QueryString["tabid"], out TabId);
         }
         if (context.Request.QueryString["mid"] != null)
         {
             Int32.TryParse(context.Request.QueryString["mid"], out ModuleId);
         }
     }
     catch (Exception ex)
     {
         ex.ToString();
         throw new HttpException(404, "Not Found");
     }
     string Language = _portalSettings.DefaultLanguage;
     if (context.Request.QueryString["language"] != null)
     {
         Language = context.Request.QueryString["language"];
     }
     else
     {
         if (context.Request.Cookies["language"] != null)
         {
             Language = context.Request.Cookies["language"].Value;
         }
     }
     if (Localization.Localization.LocaleIsEnabled(Language))
     {
         System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(Language);
         Localization.Localization.SetLanguage(Language);
     }
     string URL = "";
     bool blnClientCache = true;
     bool blnForceDownload = false;
     if (context.Request.QueryString["fileticket"] != null)
     {
         URL = "FileID=" + UrlUtils.DecryptParameter(context.Request.QueryString["fileticket"]);
     }
     if (context.Request.QueryString["userticket"] != null)
     {
         URL = "UserId=" + UrlUtils.DecryptParameter(context.Request.QueryString["userticket"]);
     }
     if (context.Request.QueryString["link"] != null)
     {
         URL = context.Request.QueryString["link"];
         if (URL.ToLowerInvariant().StartsWith("fileid="))
         {
             URL = "";
         }
     }
     if (!String.IsNullOrEmpty(URL))
     {
         UrlController objUrls = new UrlController();
         objUrls.UpdateUrlTracking(_portalSettings.PortalId, URL, ModuleId, -1);
         TabType UrlType = Globals.GetURLType(URL);
         if (UrlType != TabType.File)
         {
             URL = Common.Globals.LinkClick(URL, TabId, ModuleId, false);
         }
         if (UrlType == TabType.File && URL.ToLowerInvariant().StartsWith("fileid=") == false)
         {
             FileController objFiles = new FileController();
             URL = "FileID=" + objFiles.ConvertFilePathToFileId(URL, _portalSettings.PortalId);
         }
         if (context.Request.QueryString["clientcache"] != null)
         {
             blnClientCache = bool.Parse(context.Request.QueryString["clientcache"]);
         }
         if ((context.Request.QueryString["forcedownload"] != null) || (context.Request.QueryString["contenttype"] != null))
         {
             blnForceDownload = bool.Parse(context.Request.QueryString["forcedownload"]);
         }
         context.Response.Clear();
         try
         {
             switch (UrlType)
             {
                 case TabType.File:
                     if (TabId == Null.NullInteger)
                     {
                         if (!FileSystemUtils.DownloadFile(_portalSettings.PortalId, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload))
                         {
                             throw new HttpException(404, "Not Found");
                         }
                     }
                     else
                     {
                         if (!FileSystemUtils.DownloadFile(_portalSettings, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload))
                         {
                             throw new HttpException(404, "Not Found");
                         }
                     }
                     break;
                 case TabType.Url:
                     if (objUrls.GetUrl(_portalSettings.PortalId, URL) != null)
                     {
                         context.Response.Redirect(URL, true);
                     }
                     break;
                 default:
                     context.Response.Redirect(URL, true);
                     break;
             }
         }
         catch (ThreadAbortException ex)
         {
             ex.ToString();
         }
         catch (Exception ex)
         {
             ex.ToString();
             throw new HttpException(404, "Not Found");
         }
     }
     else
     {
         throw new HttpException(404, "Not Found");
     }
 }
 private void ParseFiles(XmlNodeList nodeFiles, int PortalId, FolderInfo objFolder)
 {
     int FileId;
     FileController objController = new FileController();
     CommonLibrary.Services.FileSystem.FileInfo objInfo;
     string fileName;
     foreach (XmlNode node in nodeFiles)
     {
         fileName = XmlUtils.GetNodeValue(node.CreateNavigator(), "filename");
         objInfo = objController.GetFile(fileName, PortalId, objFolder.FolderID);
         if (objInfo == null)
         {
             objInfo = new CommonLibrary.Services.FileSystem.FileInfo();
             objInfo.PortalId = PortalId;
             objInfo.FileName = fileName;
             objInfo.Extension = XmlUtils.GetNodeValue(node.CreateNavigator(), "extension");
             objInfo.Size = XmlUtils.GetNodeValueInt(node, "size");
             objInfo.Width = XmlUtils.GetNodeValueInt(node, "width");
             objInfo.Height = XmlUtils.GetNodeValueInt(node, "height");
             objInfo.ContentType = XmlUtils.GetNodeValue(node.CreateNavigator(), "contenttype");
             objInfo.FolderId = objFolder.FolderID;
             objInfo.Folder = objFolder.FolderPath;
             FileId = objController.AddFile(objInfo);
         }
         else
         {
             FileId = objInfo.FileId;
         }
     }
 }