session state

G

Guest

Hello Everyone, I am using the WebClient.UploadFile process to enable the
ability for my users to upload files to helpdesk tickets. Each helpdesk
ticket has its own unique value in the database. I want to be able to pass
the unique helpdesk ticket value to the UploadFile process so that the
uploaded file can be queried by ticket number (the unique ticket value). I
have tried Session State and cookies to pass the unique ticket value to the
UploadFile code. I allways receive an exception that says I have to first
use the "new" keyword to instantiate the Session State or Cookie. I know the
cookie is there because I can access the value from other webpages. It
appears that the POST method used in the UploadFile process will not allow
the use of Session state or cookies. Please help me figure out a way to pass
the helpdesk ticket unique value to the Upload process.
 
G

Guest

Here is the code: (sorry for not posting in the original)--

******* This code send the file to be uploaded to the getupload.aspx page
*****
System.Net.NetworkCredential oNC = new
System.Net.NetworkCredential("username", "password", "domain");
System.Net.WebClient oWebClient = new System.Net.WebClient();
oWebClient.Credentials = oNC;
sDirectory = FileUpload1.PostedFile.FileName.Substring(0,
FileUpload1.PostedFile.FileName.LastIndexOf("\\") + 1);
sFilename = FileUpload1.FileName;
sPath = sDirectory + sFilename;

try
{
byte[] btResponse =
oWebClient.UploadFile("http://itnb24160//foo//getupload.aspx", "POST", sPath);
Response.Write("File was uploaded successfully." +
System.Text.Encoding.ASCII.GetString(btResponse));
}
catch (Exception ex)
{
Response.Write("File was not uploaded!!" + ex.Message.ToString());
return;
}

********** Here is the getupload.aspx code **********
//This is where I would want to create a new directory for each helpdesk
ticket value and also insert the directory name and uploaded filename to the
database. I could then create a sql query: SELECT directory, filename FROM
files WHERE HelpdeskTicketId = 12345 to return the uploaded files for a
certain helpdesk ticket.

foreach (string f in Request.Files.AllKeys)
{

System.IO.Directory.CreateDirectory("C:\\inetpub\\wwwroot\\foo\\upload\\");

HttpPostedFile file = Request.Files[f];
try
{
file.SaveAs("C:\\inetpub\\wwwroot\\foo\\upload\\" +
file.FileName);
}
catch (Exception ex)
{
throw;
}

}
 

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

Top