automatt
|
| Posted: 02/28/2002, 11:54 PM |
|
Hi, I need a quick solution to getting SQL server uploads working within a codecharge-generated application in Microsoft .NET release version. I can make SQL uploads go in a separate page, but I am not sure what the different strategies are for where to put these blips of code to extend the codecharge framework for maximum reusability. Can anyone help me with a quick solution? In the interests of the free market I am posting an award.
Thanks,
Automatt
|
|
|
 |
SN
|
| Posted: 03/01/2002, 10:37 AM |
|
I did not understand your question fully.. but below are the steps to Upload a file to SQL Database using CC.
1) On the CC Form (say Form1 ) Add a new field with the Field Type as "Label" and variable name "FileUp".
2) In the Caption field you can add "File Upload" .
3) Now in the "Open" event of the Page (not the form..) add the following code
HtmlInputFile FileUpload = new HtmlInputFile();
Form1_FileUp.Controls.Add(FileUpload);
ControlCollection myCol = this.Controls;
for(int i=0; i<myCol.Count;i++)
{
if(myCol is HtmlForm)
{
((HtmlForm)myCol).Enctype ="multipart/form-data";
}
}
4)Now got to the "Before Insert" Event of the Form and add this code..
if(Request.Files.Count>0)
{ HttpPostedFile myFile = Request.Files[0];
if(myFile!=null&&myFile.FileName.Length>0)
{
System.Byte[] FileByteArray = new System.Byte[myFile.ContentLength];
System.IO.Stream StreamObject = myFile.InputStream;
//Fill the array with file Bytes...
StreamObject.Read(FileByteArray,0,myFile.ContentLength);
//ToDO: Add code to enter data into SQL Server...
}
}
5) With the above code you will be able to get a Byte Array of the Uploaded File .. now you can follow this article to learn how to save the byte array to your database..
[ http://www.codejunkies.net/tutorials.aspx?tutorialid=127 ]
Hope this helps..
|
|
|
 |
|