Harlem 98

Harlem 98

  • NA
  • 161
  • 18.9k

Error in uploading files in DB

Dec 7 2021 5:37 PM

Hello.

I'm trying to save files in DB, which should record the file as "BinaryData".

I'm using Telerik's framework RadAsyncUpload method, similar to a normal FileUpload, but when i upload the file i get the extension

"System.IO.IOException: The process cannot access the file because it is being used by another process."

and the file only gets loaded in the App_Data folder of my app, in an automatically created "RadUploadTemp" folder.

I've tried to disable the Path mentions in my SaveFile method, getting "Path not found error". Any of the available telerik demos is similar to my context. 

How do i solve this?

//my insert/update operations method
public void SaveFile(object sender, EventArgs e){ListagemTimesheet model = new ListagemTimesheet();model.IDRecursoHumano = Convert.ToInt32(rdpInvestigadorE.Text);model.IDEstadoTimesheet = Convert.ToInt32(rcbEstado.SelectedValue);model.Observações = Obervaçoestxt.Text;model.AssinaturaTimesheet = txtAssinaturaTimesheet.Text;model.DataEnvio = DataEnvio.SelectedDate.Value;if (!string.IsNullOrEmpty(Ficheiro) && FileTipo != null){model.Ficheiro = Path.GetFileNameWithoutExtension(Ficheiro);model.FileContent = fileBytes;model.FileTipo = Path.GetExtension(FileTipo);}if (!string.IsNullOrEmpty(FileID.Text) && Convert.ToInt32(FileID.Text) > 0){model.ID = Convert.ToInt32(FileID.Text);listagembll.UpdateFile(model);}else{listagembll.InsertFile(model);}//Ascx.Cs methodpublic void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e){RadAsyncUpload1.Visible = false; //falsevar liItem = new HtmlGenericControl("li");Ficheiro = e.File.FileName; // sintaxe metodoFileTipo = e.File.ContentType;e.IsValid = true;e.File.InputStream.Position = 0;fileBytes = new byte[e.File.InputStream.Length];for (int totalBytesCopied = 0; totalBytesCopied < e.File.InputStream.Length; )totalBytesCopied += e.File.InputStream.Read(fileBytes, totalBytesCopied, Convert.ToInt32(e.File.InputStream.Length) - totalBytesCopied); //conversao para bytes}//Ascx reference
Formatos permitidos: pdf,xlsx,xlsm,xls,txt   

Here you can see a DEMO, which shows the funcionality implemented with images and with their datacontext, which unfortunatly i cannot addapt to my 3 tier architecture


Answers (4)