Formview and uploading files

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I am using the formview in conjunction with the object datasource. On basic
textual data it updates fine via the the update method but I would like to
have a pdf file to upload. What is the best way to approach this. I need to
give the pdf a unique name and store it on the server and store that name in
the database. Is there anyway of intercepting the update method and doing a
find control. How do people approch this. Regards, Chris.
 
I would suggest against using BLOB's to store PDF or any other form of
data. I usually designate a directory on the server to upload the file
(jpg, bmp, pdf, doc, etc....) and then write the file name and
directory to the database.

Say the upload field name is _uploadPicture

string PicName = _uploadPicture.PostedFile.FileName;
string _imgName = (string)Session.SessionID + "_" +
PicName.Substring(PicName.LastIndexOf(@"\") + 1);
string _imgDir = "c:\\Inetpub\\wwwroot\\application_directory\\" +
@"Upload\";

_uploadPicture.PostedFile.SaveAs(_imgDir + _imgName);

AddPhoto(_usrID, _imgDir, _imgName);

The Session.SessionID is concatenated onto the image name to give it a
unique name. You could also use a GUID or whatever other convention
you can think of. This method works fine for me.

The PostedFile.SaveAs obviously uploads and saves the file to the
server.

public void AddPhoto(string _usrID, string _imgDir, string _imgName)
{
OleDbCommand cm = new OleDbCommand("_qryUploadFile", conn);

{
cm.Connection.Open();

cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.AddWithValue("@_usrID", _usrID);
cm.Parameters.AddWithValue("@_imgDir", _imgDir);
cm.Parameters.AddWithValue("@_imgName", _imgName);
cm.ExecuteNonQuery();

cm.Connection.Close();
}


I hope this helps.

- Will
 
That partly what I want but I was thinking more how to integrate that kind
of functionality with the formview's bound controls. I understand how the
checkbox or textbox bind to the data they are based on in the formview's
edit and item templates but how do I bind a fileupload and add the kind of
functionality you have illustrated below. Regards, Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top