示例#1
0
 public AraUpload(string vId, IAraObject ConteinerFather)
     : base(vId, ConteinerFather, "AraUpload")
 {
     Click               = new AraComponentEvent <EventHandler>(this, "Click");
     PathSaveFiles       = AraTools.GetPath() + "UploadFiles\\";
     this.EventInternal += this_EventInternal;
     this.MinWidth       = 150;
     this.MinHeight      = 50;
     this.Width          = 110;
     this.Height         = 25;
 }
示例#2
0
        private void this_EventInternal(String vFunction)
        {
            switch (vFunction.ToUpper())
            {
            case "CLICK":
                Click.InvokeEvent(this, new EventArgs());
                break;

            case "SENDFILE":
            {
                Tick Tick = Tick.GetTick();
                try
                {
                    //string vFileName = Client.Page.Request["qqfile"];

                    String filename;

                    if (Tick.Page.Request.Files.AllKeys.Length > 0)
                    {
                        filename = HttpUtility.UrlDecode(Tick.Page.Request.Files[0].FileName);
                    }
                    else
                    {
                        filename = HttpUtility.UrlDecode(Tick.Page.Request.Headers["X-File-Name"]);
                    }



                    bool Permitido = true;
                    if (ReceiveFile.InvokeEvent != null)
                    {
                        Permitido = ReceiveFile.InvokeEvent(filename);
                    }


                    if (Permitido)
                    {
                        try
                        {
                            if (!Directory.Exists(PathSaveFiles))
                            {
                                Directory.CreateDirectory(PathSaveFiles);
                            }
                            if (File.Exists(Path.Combine(PathSaveFiles, Path.GetFileName(filename))))
                            {
                                File.Delete(Path.Combine(PathSaveFiles, Path.GetFileName(filename)));
                            }

                            if (Tick.Page.Request.Files.AllKeys.Length > 0)     // IE
                            {
                                HttpPostedFile file = Tick.Page.Request.Files[0];
                                file.SaveAs(Path.Combine(PathSaveFiles, Path.GetFileName(filename)));
                            }
                            else     // Outros
                            {
                                using (Stream inputStream = HttpContext.Current.Request.InputStream)
                                {
                                    using (FileStream fileStream = new FileStream(Path.Combine(PathSaveFiles, Path.GetFileName(filename)), FileMode.OpenOrCreate))
                                    {
                                        inputStream.CopyTo(fileStream);
                                        fileStream.Close();
                                    }
                                }
                            }

                            Tick.Script.CallObject(this);
                            Tick.Script.Send("vObj.ResponseUploadJson({success:true, name:\"" + AraTools.StringToStringJS(filename) + "\"});");

                            try
                            {
                                if (ReceiveFileComplite != null)
                                {
                                    ReceiveFileComplite.InvokeEvent(Path.GetFileName(filename));
                                }
                            }
                            catch { }
                            // Codigo para receber arquivo
                        }
                        catch (Exception err)
                        {
                            this.TickScriptCall();
                            Tick.Script.Send("vObj.ResponseUploadJson({'error': 'Falha ao receber arquivo. " + AraTools.StringToStringJS(err.Message) + "'});");
                        }
                    }
                    else
                    {
                        this.TickScriptCall();
                        Tick.Script.Send("vObj.ResponseUploadJson({'error': 'Arquivo não permitido'});");
                    }
                }
                catch (Exception err)
                {
                    this.TickScriptCall();
                    Tick.Script.Send("vObj.ResponseUploadJson({'error': 'Falha generica ao receber arquivo. " + AraTools.StringToStringJS(err.Message) + "'});");
                }
            }
            break;
            }
        }
示例#3
0
 public override void ExceptionAplication(Exception err)
 {
     AraTools.Alert(err.Message);
 }