Esempio n. 1
0
        public static string GetSavedFile(Telerik.Web.UI.UploadedFile fUploader, bool autoGenerateName)
        {
            string guid = string.Empty;

            if (fUploader != null)
            {
                try
                {
                    if (!fUploader.FileName.Contains('.'))
                        return guid;

                    if (autoGenerateName)
                    {
                        guid = Guid.NewGuid().ToString();
                        guid += fUploader.GetExtension();
                    }
                    else
                        guid = fUploader.GetName();
                    if (File.Exists(ExpressoConfig.GeneralConfigElement.GetPhysicalUploadPath + "\\" + guid))
                    {
                        guid = fUploader.GetNameWithoutExtension() + "_" + Guid.NewGuid().ToString().Substring(0, 3).ToString() + fUploader.GetExtension();
                    }
                    fUploader.SaveAs(ExpressoConfig.GeneralConfigElement.GetPhysicalUploadPath + "\\" + guid);

                }


                catch (Exception ex)
                {
                    throw ex;
                }

            }
            return guid;
        }
		private void FillFileInfo(Telerik.Web.UI.UploadedFile file, ref Services.FileSystem.FileInfo fileInfo)
		{
			//The core API expects the path to be stripped off the filename
			fileInfo.FileName = ((file.FileName.Contains("\\")) ? Path.GetFileName(file.FileName) : file.FileName);
			fileInfo.Extension = file.GetExtension();
			if (fileInfo.Extension.StartsWith("."))
			{
				fileInfo.Extension = fileInfo.Extension.Remove(0, 1);
			}

			fileInfo.ContentType = FileSystemUtils.GetContentType(fileInfo.Extension);

			FillImageInfo(file.InputStream, ref fileInfo);
		}
Esempio n. 3
0
        public static string GetSavedFileforGallery(Telerik.Web.UI.UploadedFile fUploader, bool autoGenerateName, bool generateThumbnail)
        {
            string guid = string.Empty;

            if (fUploader != null)
            {
                try
                {

                    if (!fUploader.FileName.Contains('.'))
                        return guid;

                    if (autoGenerateName)
                    {
                        guid = Guid.NewGuid().ToString();
                        guid += fUploader.GetExtension();
                    }
                    else
                        guid = fUploader.GetName();
                    if (!Directory.Exists((ConfigContext.GetGalleryUploadPath)))
                    {
                        Directory.CreateDirectory((ConfigContext.GetGalleryUploadPath));
                    }
                    fUploader.SaveAs(ConfigContext.GetGalleryUploadPath + guid);

                    //Generate Thumbnail
                    if (generateThumbnail)
                    {
                        Bitmap thumbnail = CreateThumbnail(ConfigContext.GetGalleryUploadPath + guid, 180, 140);
                        thumbnail.Save(ConfigContext.GetGalleryUploadPath + "Thumb-" + guid);
                    }


                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
            return guid;
        }