public void InstantiateIn(Control container) { RadUpload uploadAttachment = new RadUpload(); container.Controls.Add(uploadAttachment); uploadAttachment.ID = ControlId; uploadAttachment.ControlObjectsVisibility = ControlObjectsVisibility.None; }
public void InitializeComponent() { if (_contentLoaded) { return; } _contentLoaded = true; System.Windows.Application.LoadComponent(this, new System.Uri("/Procbel.Apps.Silverlight.Modules.Incidencias;component/Views/EditTicketUserContr" + "ol.xaml", System.UriKind.Relative)); this.HtmlProvider = ((HtmlDataProvider)(this.FindName("HtmlProvider"))); this.richTextBox = ((RadRichTextBox)(this.FindName("richTextBox"))); this.uploadBackground = ((System.Windows.Shapes.Rectangle)(this.FindName("uploadBackground"))); this.RadUpload1 = ((RadUpload)(this.FindName("RadUpload1"))); }
public System.Collections.Specialized.IOrderedDictionary ExtractValues(Control container) { OrderedDictionary od = new OrderedDictionary(); RadUpload uploadAttachment = (RadUpload)container.FindControl(ControlId); if (uploadAttachment.UploadedFiles.Count > 0) { UploadedFile fileStream = uploadAttachment.UploadedFiles[0]; byte[] fileData = new byte[fileStream.ContentLength]; fileStream.InputStream.Read(fileData, 0, fileStream.ContentLength); od.Add(DataField, fileData); } else { od.Add(DataField, null); } return(od); }
protected void rgChildData_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item) { DayCarePL.ChildDataProperties objChildData = e.Item.DataItem as DayCarePL.ChildDataProperties; Image imgChild = e.Item.FindControl("imgPhoto") as Image; HyperLink hlChildEnrollmentStatus = e.Item.FindControl("hlChildEnrollmentStatus") as HyperLink; HyperLink hlChildAbsentHistory = e.Item.FindControl("hlChildAbsentHistory") as HyperLink; HyperLink hlChildSchedule = e.Item.FindControl("hlChildSchedule") as HyperLink; if (!string.IsNullOrEmpty(objChildData.Photo)) { imgChild.ImageUrl = "../ChildImages/" + objChildData.Photo; } else { if (objChildData.Gender == true) { imgChild.ImageUrl = "../ChildImages/boy.png"; } else { imgChild.ImageUrl = "../ChildImages/girl.png"; } } hlChildEnrollmentStatus.NavigateUrl = "ChildEnrollmentStatus.aspx?Id=" + objChildData.Id; hlChildAbsentHistory.NavigateUrl = "ChildAbsentHistory.aspx?Id=" + objChildData.Id; hlChildSchedule.NavigateUrl = "ChildProgEnrollment.aspx?ChildDataId=" + objChildData.Id; } if (e.Item is GridEditableItem && e.Item.IsInEditMode) { UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); RadUpload upload = userControl.FindControl("fupImage") as RadUpload; MasterAjaxManager = this.Page.Master.FindControl("RadAjaxManager1") as Telerik.Web.UI.RadAjaxManager; MasterAjaxManager.ResponseScripts.Add(string.Format("window['UploadId'] = '{0}';", upload.ClientID)); } }
protected override void ExecuteOverride(object parameter) { this.Owner.CommitTool(); RadBitmap image = this.Owner.Image; RadUpload upload = new RadUpload(); MemoryStream stream = new MemoryStream(); PngFormatProvider png = new PngFormatProvider(); png.Export(image, stream); stream.Seek(0, SeekOrigin.Begin); RadUploadSelectedFile file = new RadUploadSelectedFile(stream, "image" + image.GetHashCode() + ".png"); upload.TargetFolder = "UploadFolder"; upload.UploadServiceUrl = "SampleUploadHandler.ashx"; upload.CurrentSession.SelectedFiles.Add(file); upload.PrepareSelectedFilesForUpload(); upload.UploadFinished += new RoutedEventHandler(upload_UploadFinished); upload.StartUpload(); }
public void OnFilesSelected() { // arrange var vm = new FieldFileViewModel(); var radUpload = new RadUpload(); var called = false; Mock.Arrange(() => radUpload.CancelUpload()).DoInstead(() => called = true); var fileInfo = Mock.Create<FileInfo>(Behavior.CallOriginal); var radUploadSelectedFile = new RadUploadSelectedFile(fileInfo); var e = new FilesSelectedEventArgs(new List<RadUploadSelectedFile> { radUploadSelectedFile }); var fileProcess = Mock.Create<IFileProcess>(Behavior.Loose); fileProcess.OriginalFileName = "1.txt"; Mock.NonPublic.Arrange<IFileProcess>(vm, "CurrentFileProcess").Returns(fileProcess); // act vm.OnFilesSelected(radUpload, e); // assert Assert.AreEqual("The process cannot access file '1.txt' because it is being used by another process.", vm.Message); Assert.AreEqual(FileControlMode.NotifyFail, vm.CurrentState); Assert.IsTrue(called); // arrange vm.Message = null; called = false; vm.CurrentState = FileControlMode.Download; Mock.Arrange(() => fileInfo.Directory).Throws<Exception>(); Mock.Arrange(() => radUploadSelectedFile.Size).Returns(1); Mock.NonPublic.Arrange<ulong>(vm, "MaxFileSize").Returns(0); // act vm.OnFilesSelected(radUpload, e); // assert Assert.AreEqual("Maximum file size is 0.0 Mb", vm.Message); Assert.AreEqual(FileControlMode.NotifyFail, vm.CurrentState); Assert.IsTrue(called); // arrage vm.Message = null; called = false; vm.CurrentState = FileControlMode.Download; Mock.NonPublic.Arrange<ulong>(vm, "MaxFileSize").Returns(2); // act vm.OnFilesSelected(radUpload, e); // assert Assert.IsNull(vm.Message); Assert.AreNotEqual(FileControlMode.NotifyFail, vm.CurrentState); Assert.IsFalse(called); }
private bool ProcessUploadedFiles(RadUpload oUpload, IASpot oIASpot) { if (oUpload.UploadedFiles.Count > 0) { if (oIASpot.IASpotStatusID == ApplicationContext.GetSpotStatusID(SpotStatus.NeedsFix)) { // Mark all older files as 'old' by appending the word to their filenames. foreach (var oIASpotFIle in oIASpot.IASpotFiles.Where(row => row.IASpotFileTypeID == ApplicationContext.GetSpotFileTypeID(SpotFileTypes.Talent))) { var sNewFilename = string.Empty; var sExtension = string.Empty; var iIndex = oIASpotFIle.Filename.LastIndexOf("."); if (iIndex > 0) { sExtension = oIASpotFIle.Filename.Substring(iIndex, oIASpotFIle.Filename.Length - iIndex); } sNewFilename = string.Format("{0}_old{1}", MemberProtect.Utility.Left(oIASpotFIle.Filename, iIndex), sExtension); oIASpotFIle.Filename = sNewFilename; DataAccess.SubmitChanges(); } } foreach (UploadedFile oFile in oUpload.UploadedFiles) { // Create file record var oIASpotFile = new IASpotFile(); oIASpotFile.IASpotFileTypeID = ApplicationContext.GetSpotFileTypeID(SpotFileTypes.Talent); oIASpotFile.Filename = oFile.GetName(); oIASpotFile.FilenameUnique = string.Format("{0}{1}", Guid.NewGuid(), oFile.GetExtension()); oIASpotFile.FileSize = oFile.ContentLength; oIASpotFile.IsDeletable = true; oIASpotFile.CreatedDateTime = DateTime.Now; oIASpot.IASpotFiles.Add(oIASpotFile); DataAccess.SubmitChanges(); // Save physical file under a new name oFile.SaveAs(string.Format("{0}{1}", ApplicationContext.UploadPath, oIASpotFile.FilenameUnique)); } return true; } else { return false; } }