
11 Answers, 1 is accepted
I suggest that you take a look at the following demo. It demonstrates a scenario closely related to what you are trying achieve.
Greetings,
Genady Sergeev
the Telerik team

When the Process method of the handler is fired, the file has been already saved by the uploader; if it is possible i would like to have it only in memory.
The files are always buffered to the temp folder since buffering them enirely into the memory is very likely to cause serious impact on the web server. Imagine what would happen on a shared hosting, for example.
Kind regards,
Genady Sergeev
the Telerik team


Please have a look at the following sample code I tried to save uploaded files in database.
ASPX:
<
telerik:RadAsyncUpload
runat
=
"server"
ID
=
"RadAsyncUpload1"
TargetFolder
=
"~/Images/Img/"
AllowedFileExtensions
=
".jpg"
MaxFileSize
=
"57971152"
MultipleFileSelection
=
"Automatic"
UploadedFilesRendering
=
"BelowFileInput"
OnFileUploaded
=
"RadAsyncUpload1_FileUploaded"
>
</
telerik:RadAsyncUpload
>
<
br
/>
<
telerik:RadButton
ID
=
"RadButton1"
runat
=
"server"
Text
=
"Submit"
>
</
telerik:RadButton
>
C#:
protected
void
RadAsyncUpload1_FileUploaded(
object
sender, FileUploadedEventArgs e)
{
Stream fileStream = e.File.InputStream;
byte
[] attachmentBytes =
new
byte
[fileStream.Length];
fileStream.Read(attachmentBytes, 0, Convert.ToInt32(fileStream.Length));
System.Data.SqlClient.SqlConnection conn =
null
;
try
{
try
{
conn =
new
System.Data.SqlClient.SqlConnection(
ConfigurationManager.ConnectionStrings[
"NorthwindConnectionString"
].ConnectionString);
conn.Open();
System.Data.SqlClient.SqlCommand insertCommand =
new
System.Data.SqlClient.SqlCommand(
"Insert into [Pictable] (msgid, pic1) Values (1, @Pic)"
, conn);
insertCommand.Parameters.Add(
"@Pic"
, SqlDbType.VarBinary).Value = attachmentBytes;
int
queryResult = insertCommand.ExecuteNonQuery();
}
catch
(Exception ex)
{
}
}
finally
{
if
(conn !=
null
)
{
fileStream.Close();
conn.Close();
}
}
}
Thanks,
Shinu.



Why do you think that the demo is not working. Its purpose is to demonstrates how to upload files into the Database? The DisableChunkUpload property specify if the file will be uploaded on chunks or at once, but it has nothing to do with the Temporary folder. However it is true that when this property is enabled the selected file will not be uploaded to the Temporary folder, it will be transfer at once to the handler with the HttpContext object.
By design RadAsyncUpload always create a TemporaryFolder to verify if the control has write permissions to the File System. Note that the default configuration of the control uses uploading on chunking. If you cannot use the App_Data\RadUpload folder, than you can change it by setting the TargetFolder property.
If you would like such functionality that allow you to control whether the TemporaryFolder will be created or not you can submit a new feature request.
Hristo Valyavicharski
Telerik

I have a CSV file with ~200 000 records to load into a database. In my application I use Entity Framework 6.1.3 to communicate with a database. Can I still utilize the RadAsyncUpload control to simply import data into a database? Or there's another better solution for this?
Regards,
Artur
AsyncUpload gives you access to the Input Stream of the Uploaded Files, so can use this:
<
telerik:RadAsyncUpload
runat
=
"server"
ID
=
"async"
OnFileUploaded
=
"async_FileUploaded"
RenderMode
=
"Lightweight"
AllowedFileExtensions
=
".csv"
>
</
telerik:RadAsyncUpload
>
<
telerik:RadButton
runat
=
"server"
ID
=
"btn"
Text
=
"Submit"
></
telerik:RadButton
>
protected
void
async_FileUploaded(
object
sender, FileUploadedEventArgs e)
{
StreamReader csvreader =
new
StreamReader(e.File.InputStream);
while
(!csvreader.EndOfStream)
{
var line = csvreader.ReadLine();
var values = line.Split(
';'
);
System.Diagnostics.Debug.WriteLine(line);
}
}
I hope this helps.
Regards,
Hristo Valyavicharski
Telerik