public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
        {
            try
            {
                string virtualPath = FileSystemValidation.ToVirtualPath(path);

                string returnValue = DNNValidator.OnCreateFile(FileSystemValidation.CombineVirtualPath(virtualPath, name), file.ContentLength);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                var folder = DNNValidator.GetUserFolder(virtualPath);

                var fileInfo = new DotNetNuke.Services.FileSystem.FileInfo();
                FillFileInfo(file, ref fileInfo);

                //Add or update file
                FileManager.Instance.AddFile(folder, name, file.InputStream);

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, name));
            }
        }
Exemple #2
0
        public static FileMessage UploadFile(ref Telerik.Web.UI.UploadedFile file, String filePath)
        {
            Impersonate oImpersonate    = new Impersonate();
            Boolean     wasImpersonated = Impersonate.isImpersonated();

            try
            {
                if (!wasImpersonated && oImpersonate.ImpersonateValidUser() == FileMessage.ImpersonationFailed)
                {
                    return(FileMessage.ImpersonationFailed);
                }
                else
                {
                    file.SaveAs(filePath);
                    return(FileMessage.FileCreated);
                }
            }
            catch
            {
                if (!wasImpersonated)
                {
                    oImpersonate.UndoImpersonation();
                }
                return(FileMessage.Catch);
            }
            finally
            {
                if (!wasImpersonated)
                {
                    oImpersonate.UndoImpersonation();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Stores the file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="path">The path.</param>
        /// <param name="name">The name.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns></returns>
        public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
        {
            //int fileLength = (int)file.InputStream.Length;
            //byte[] content = new byte[fileLength];
            //file.InputStream.Read(content, 0, fileLength);
            //string fullPath = CombinePath(path, name);
            //if (!Object.Equals(DataServer.GetItemRow(fullPath), null))
            //{
            //    DataServer.ReplaceItemContent(fullPath, content);
            //}
            //else
            //{
            //    DataServer.CreateItem(name, path, file.ContentType, false, fileLength, content);
            //}
            int fileLength = (int)file.InputStream.Length;

            byte[] content = new byte[fileLength];
            file.InputStream.Read(content, 0, fileLength);

            switch (path.TrimEnd(slashArray))
            {
            case "/User":

                UserFile userFile = new UserFile();
                userFile.FileName = name;
                userFile.Size     = fileLength;
                userFile.UserID   = KbContext.CurrentUserId;

                KbContext.CurrentKb.ManagerUserFile.Save(userFile);

                KbContext.CurrentKb.ManagerUserFile.SetData(userFile.UserFileID, content);

                break;

            case "/Knowledge":
                if (!knowledgeID.HasValue)
                {
                    return("Knowlede not saved");
                }

                FileInclude fileInclude = new FileInclude();
                fileInclude.FileName    = name;
                fileInclude.Size        = fileLength;
                fileInclude.KnowledgeID = knowledgeID.Value;

                var manager = KbContext.CurrentKb.ManagerFileInclude;
                manager.Save(fileInclude);
                manager.SetData(fileInclude.FileIncludeID, content);

                break;
            }
            return(string.Empty);
        }
Exemple #4
0
        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);
        }
    public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
    {
        string physicalPath = this.GetPhysicalFromVirtualPath(path);

        if (physicalPath == null)
        {
            return(string.Empty);
        }

        physicalPath = PathHelper.AddEndingSlash(physicalPath, '\\') + name;
        file.SaveAs(physicalPath);


        // Returns the path to the newly created file
        return(PathHelper.AddEndingSlash(path, '/') + name);
    }
 public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
 {
     //int fileLength = Convert.ToInt32(file.InputStream.Length);
     //byte[] content = new byte[fileLength];
     //file.InputStream.Read(content, 0, fileLength);
     //string fullPath = CombinePath(path, name);
     //if (!Object.Equals(DataServer.GetItemRow(fullPath), null))
     //{
     //    DataServer.ReplaceItemContent(fullPath, content);
     //}
     //else
     //{
     //    DataServer.CreateItem(name, path, file.ContentType, false, fileLength, content);
     //}
     return(string.Empty);
 }
    protected void RadUpload1_FileExists1(object sender, Telerik.Web.UI.Upload.UploadedFileEventArgs e)
    {
        int counter = 1;

        Telerik.Web.UI.UploadedFile file = e.UploadedFile;
        string targetFolder   = Server.MapPath("~/App_Uploads_Img/" + DropDownList1I.SelectedItem.Text + "/");
        string targetFileName = Path.Combine(targetFolder,
                                             file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension());

        while (System.IO.File.Exists(targetFileName))
        {
            counter++;
            targetFileName = Path.Combine(targetFolder,
                                          file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension());
        }

        file.SaveAs(targetFileName);
        GC.Collect();
    }
Exemple #8
0
        public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
        {
            try
            {
                // TODO: Create entries in .resx for these messages
                Uri uri;
                if (!Uri.TryCreate(name, UriKind.Relative, out uri))
                {
                    ShowMessage(string.Format("The file {0} cannot be uploaded because it would create an invalid URL. Please, rename the file before upload.", name));
                    return("");
                }

                var invalidChars = new[] { '<', '>', '*', '%', '&', ':', '\\', '?', '+' };
                if (invalidChars.Any(uri.ToString().Contains))
                {
                    ShowMessage(string.Format("The file {0} contains some invalid characters. The file name cannot contain any of the following characters: {1}", name, new String(invalidChars)));
                    return("");
                }

                string virtualPath = FileSystemValidation.ToVirtualPath(path);

                string returnValue = DNNValidator.OnCreateFile(FileSystemValidation.CombineVirtualPath(virtualPath, name), file.ContentLength);
                if (!string.IsNullOrEmpty(returnValue))
                {
                    return(returnValue);
                }

                var folder = DNNValidator.GetUserFolder(virtualPath);

                var fileInfo = new Services.FileSystem.FileInfo();
                FillFileInfo(file, ref fileInfo);

                //Add or update file
                FileManager.Instance.AddFile(folder, name, file.InputStream);

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, name));
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Callback = Request.QueryString["Callback"];

            _4screen.CSB.Extensions.Business.TrackingManager.TrackEventPage(null, null, IsPostBack, LogSitePageType.WizardSpezial);

            if (!string.IsNullOrEmpty(Request.QueryString["CN"]))
            {
                folderId = Request.QueryString["CN"];
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["UI"]))
            {
                folderId = Request.QueryString["UI"];
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["ParentId"]))
            {
                folderId = Request.QueryString["ParentId"];
            }

            if (RadUpload.UploadedFiles.Count > 0)
            {
                _4screen.CSB.ImageHandler.Business.ImageHandler imageHandler = new _4screen.CSB.ImageHandler.Business.ImageHandler(_4screen.CSB.Common.SiteConfig.MediaDomainName, ConfigurationManager.AppSettings["ConverterRootPath"], folderId, null, true, Server.MapPath("/Configurations"));

                Telerik.Web.UI.UploadedFile uploadedFile = RadUpload.UploadedFiles[0];
                string originalExtension = uploadedFile.GetName().Substring(uploadedFile.GetName().LastIndexOf('.'));
                string archiveFolder     = string.Format(@"{0}\{1}\BG\{2}", System.Configuration.ConfigurationManager.AppSettings["ConverterRootPathMedia"], folderId, PictureVersion.A);
                if (!Directory.Exists(archiveFolder))
                {
                    Directory.CreateDirectory(archiveFolder);
                }
                string archiveFilename = string.Format(@"{0}\{1}{2}", archiveFolder, imageHandler.ImageName, originalExtension);
                uploadedFile.SaveAs(archiveFilename);

                imageHandler.DoConvert(archiveFilename, actionProfileResizeLarge, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                imageHandler.DoConvert(archiveFilename, actionProfileResizeExtraSmall, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
            }

            LoadPictures();
        }
Exemple #10
0
    public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
    {
        string physicalPath = this.GetPhysicalFromVirtualPath(path);

        if (physicalPath == null)
        {
            return(string.Empty);
        }

        physicalPath = PathHelper.AddEndingSlash(physicalPath, '\\') + name;
        var ffile = new System.IO.FileInfo(physicalPath);

        if (ffile.Directory != null && !ffile.Directory.Exists)
        {
            ffile.Directory.Create();
        }
        file.SaveAs(physicalPath);


        // Returns the path to the newly created file
        return(PathHelper.AddEndingSlash(path, '/') + name);
    }
Exemple #11
0
    protected void btnAgregarImagen_Click(object sender, ImageClickEventArgs e)
    {
        lblError.Text = "";

        if (rdlOpcion.SelectedValue == "D")
        {
            if (lblReferencia.Text != "")
            {
                byte[] imagen        = null;
                bool   archivoValido = false;
                string extension     = "";

                if (AsyncUpload1.UploadedFiles.Count == 0)
                {
                    lblError.Text = "Debe indicar el o los documentos a cargar";
                }
                else
                {
                    int   idEmpresa = 0;
                    int   cliente   = 0;
                    Datos fotos     = new Datos();
                    try { idEmpresa = Convert.ToInt32(Request.QueryString["e"].ToString()); }
                    catch (Exception) { Response.Redirect("Default.aspx"); }
                    try { cliente = Convert.ToInt32(lblIdCliente.Text); }
                    catch (Exception) { cliente = 0; }
                    //Documentos

                    try
                    {
                        string ruta     = Server.MapPath("~/TMP");
                        string filename = "";
                        // Si el directorio no existe, crearlo
                        if (!Directory.Exists(ruta))
                        {
                            Directory.CreateDirectory(ruta);
                        }
                        int documentos = AsyncUpload1.UploadedFiles.Count;
                        int guardados  = 0;
                        for (int i = 0; i < documentos; i++)
                        {
                            filename = AsyncUpload1.UploadedFiles[i].FileName;
                            string[] segmenatado = filename.Split(new char[] { '.' });
                            archivoValido = validaArchivo(segmenatado[1]);
                            extension     = segmenatado[1];
                            string archivo = String.Format("{0}\\{1}", ruta, filename);
                            try
                            {
                                FileInfo file = new FileInfo(archivo);
                                // Verificar que el archivo no exista
                                if (File.Exists(archivo))
                                {
                                    file.Delete();
                                }

                                if (extension.ToUpper() != "PDF")
                                {
                                    System.Drawing.Image img = System.Drawing.Image.FromStream(AsyncUpload1.UploadedFiles[i].InputStream);
                                    img.Save(archivo);
                                    imagen = Imagen_A_Bytes(archivo);
                                }
                                else
                                {
                                    Telerik.Web.UI.UploadedFile up = AsyncUpload1.UploadedFiles[i];
                                    up.SaveAs(archivo);
                                    imagen = File.ReadAllBytes(archivo);
                                }
                            }
                            catch (Exception) { imagen = null; }
                            if (imagen != null)
                            {
                                string identificadorProceso = ddlEstatus.SelectedValue;
                                bool   agregado             = datos.agregaDocumentosCliente(cliente, imagen, extension, lblReferencia.Text, idEmpresa, identificadorProceso);
                                if (agregado)
                                {
                                    guardados++;
                                }
                            }
                        }
                        lblError.Text = "Se guardaron " + guardados.ToString() + " imagenes de " + documentos.ToString() + " seleccionadas.";
                    }
                    catch (Exception) { imagen = null; }
                    int empresa = 0;
                    try
                    {
                        empresa = Convert.ToInt32(Request.QueryString["e"].ToString());
                        DataSet imagenes = fotos.obtieneDoctos(lblReferencia.Text, empresa, cliente);
                        DataListFotosDanos.DataSource = imagenes;
                        DataListFotosDanos.DataBind();
                    }
                    catch (Exception)
                    {
                        DataListFotosDanos.DataSource = null;
                        DataListFotosDanos.DataBind();
                    }
                }
            }
            else
            {
                lblError.Text = "Debe seleccionar un cliente";
            }
        }
        else
        {
            lblError.Text = "La acción de agregar solo es accesible en la opción documentos";
        }
    }
Exemple #12
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     Telerik.Web.UI.UploadedFile file = this.RadUpload1.UploadedFiles[0];
     file.SaveAs(Server.MapPath("/") + file.FileName);
 }
Exemple #13
0
        private void BindValidResults()
        {
            _4screen.CSB.ImageHandler.Business.ImageHandler imageHandler = new _4screen.CSB.ImageHandler.Business.ImageHandler(_4screen.CSB.Common.SiteConfig.MediaDomainName, ConfigurationManager.AppSettings["ConverterRootPath"], dataObject.UserID.ToString(), objectId.ToString(), true, Server.MapPath("/Configurations"));

            if (RadUpload1.UploadedFiles.Count > 0)
            {
                pnlUploadFinish.Visible = false;
                Telerik.Web.UI.UploadedFile uploadedFile = RadUpload1.UploadedFiles[0];
                if (!string.IsNullOrEmpty(Request.QueryString["TemplateID"]))
                {
                    Guid templateId = Request.QueryString["TemplateID"].ToGuid();
                    template = DataObject.Load <DataObject>(templateId, null, false);
                }
                if (template != null && template.State != ObjectState.Added)
                {
                    Helper.SetActions(Helper.GetPictureFormatFromFilename(uploadedFile.GetName()), template.ObjectType, out actionProfileCropCheckAndArchive, out actionProfileResizeLarge, out actionProfileResizeMedium, out actionProfileResizeSmall, out actionProfileResizeExtraSmall, out actionProfileCrop, imageTypes);
                }
                else
                {
                    Helper.SetActions(Helper.GetPictureFormatFromFilename(uploadedFile.GetName()), dataObject.ObjectType, out actionProfileCropCheckAndArchive, out actionProfileResizeLarge, out actionProfileResizeMedium, out actionProfileResizeSmall, out actionProfileResizeExtraSmall, out actionProfileCrop, imageTypes);
                }
                string originalExtension = uploadedFile.GetName().Substring(uploadedFile.GetName().LastIndexOf('.'));
                string archivedFilename  = System.IO.Path.Combine(imageHandler.GetPhysicalImagePath(actionProfileCropCheckAndArchive), imageHandler.ImageName + originalExtension);
                uploadedFile.SaveAs(archivedFilename, true);

                imageHandler.DoConvert(archivedFilename, actionProfileCropCheckAndArchive, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                archivedFilename = imageHandler.TargetImage;
                int originalImageHeight    = imageHandler.ImageInfo.Height;
                int originalImageWidth     = imageHandler.ImageInfo.Width;
                int cropLimitHeight        = imageHandler.OriginalCropHeight(actionProfileCropCheckAndArchive);
                int cropLimitWidth         = imageHandler.OriginalCropWidth(actionProfileCropCheckAndArchive);
                int maxVisualWidthOrHeight = imageHandler.GetMaxVisualWidthOrHeight(actionProfileCropCheckAndArchive);

                if (originalImageHeight < cropLimitHeight && originalImageWidth < cropLimitWidth) // No need for cropping
                {
                    imageHandler.DoConvert(archivedFilename, actionProfileResizeExtraSmall, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                    imageHandler.DoConvert(archivedFilename, actionProfileResizeSmall, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                    if (actionProfileResizeMedium != null)
                    {
                        imageHandler.DoConvert(archivedFilename, actionProfileResizeMedium, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                    }
                    imageHandler.DoConvert(archivedFilename, actionProfileResizeLarge, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                    SaveDataObject(imageHandler.ImageName);

                    if (string.IsNullOrEmpty(Request.QueryString["ReturnURL"]))
                    {
                        litScript.Text = "<script language=\"javascript\">$telerik.$(function() { RefreshParentPage(true); CloseWindow(); } );</script>";
                    }
                    else
                    {
                        litScript.Text = string.Format("<script language=\"javascript\">$telerik.$(function() {{ RedirectParentPage('{0}'); CloseWindow(); }} );</script>", Encoding.ASCII.GetString(Convert.FromBase64String(Request.QueryString["ReturnURL"])));
                    }
                }
                else
                {
                    ViewState["sourceImg"]   = archivedFilename;
                    ViewState["ImageWidth"]  = originalImageWidth;
                    ViewState["ImageHeight"] = originalImageHeight;
                    ViewState["MaxSize"]     = maxVisualWidthOrHeight;

                    pnlCroping.Visible      = true;
                    pnlUploadFinish.Visible = false;
                    pnlUpload.Visible       = false;
                    if (!string.IsNullOrEmpty(Request.QueryString["TemplateID"]))
                    {
                        this.PnlTitle.Visible = true;
                    }

                    if (originalImageHeight > originalImageWidth && originalImageHeight > maxVisualWidthOrHeight)
                    {
                        Crop.CroppedImageHeight = maxVisualWidthOrHeight;
                        Crop.CroppedImageWidth  = (int)((float)maxVisualWidthOrHeight * (float)originalImageWidth / (float)originalImageHeight);
                    }
                    else if (originalImageHeight < originalImageWidth && originalImageWidth > maxVisualWidthOrHeight)
                    {
                        Crop.CroppedImageHeight = (int)((float)maxVisualWidthOrHeight * (float)originalImageHeight / (float)originalImageWidth);
                        Crop.CroppedImageWidth  = maxVisualWidthOrHeight;
                    }
                    else if (originalImageWidth > maxVisualWidthOrHeight)
                    {
                        Crop.CroppedImageHeight = maxVisualWidthOrHeight;
                        Crop.CroppedImageWidth  = maxVisualWidthOrHeight;
                    }
                    else
                    {
                        Crop.CroppedImageHeight = originalImageHeight;
                        Crop.CroppedImageWidth  = originalImageWidth;
                    }
                    Crop.AllowQualityLoss = true;

                    FileStream stream = File.Open(archivedFilename, FileMode.Open);
                    byte[]     buffer = new byte[stream.Length];
                    stream.Read(buffer, 0, buffer.Length);
                    stream.Dispose();
                    Crop.SourceImage = buffer;
                }
            }
        }