Click to See Complete Forum and Search --> : How to solve this problem


saimukesh
July 26th, 2006, 07:51 AM
Hi, iam having a peculiar problem.My problem is i am uploading a file using html input field.So now my problem is i want that the file name of that particular uploaded file in the text file wich i am creating in the button click event..

suppose i uploaded asdfs.txt ,then in the button click i am creating one text file and and i should append the uploaded filename at the end of the text file created..But the filename value is vanishing for some reasons after execuitng the upload procedure...So i am confused here.I placed a break point and excuted after executing the proceudre to upload file then the variable filename is losing its its value.So after clicking the button the filename is not displaying...
WHAT MIGHT BE THE PROBLEM

Fishdawg65
July 26th, 2006, 09:27 AM
I think we need to see some code.

saimukesh
July 26th, 2006, 11:47 PM
Hi,thanks for caring me here is my code just check it....

In the procedure of Upload_click , i am uploading a file wich is from html input filed...So my code is like

Sub Upload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
FileName.InnerHtml = MyFile.PostedFile.FileName
FileContent.InnerHtml = MyFile.PostedFile.ContentType
FileSize.InnerHtml = MyFile.PostedFile.ContentLength
UploadDetails.Visible = True
' Dim writer As StreamWriter
strFileName = MyFile.PostedFile.FileName
c = System.IO.Path.GetFileNameWithoutExtension(strFileName) ' only the attched file name not its path
Try
MyFile.PostedFile.SaveAs("C:\client\" + c)
Span1.InnerHtml = "Your File Uploaded Sucessfully at server as : C:\client\" & c

"c" is a global variable as well as strfilename too..
So files are uploaded perfectly in the specified folder C:\client.And C is having the filename stored...

next in the button_click event I am creating a file

Dim writer As StreamWriter
writer = File.CreateText(MapPath("remote5.bat"))
writer.WriteLine("c:")
writer.WriteLine("cd\wiredraw")
writer.WriteLine("call C:\ABAQUS\Commands\abaqus.bat cae -noGui " & c & ".py")
writer.Close()

but here after running,the value of "c" is bcomes nothing..

The value of "c" is bcomes nothing when it comes to button_click.So my doubt is i declared "c" as global.So why the value of "c" is showing nothing....

Fishdawg65
July 27th, 2006, 09:37 AM
In your page load, do you have any code that makes c = ""? Where else do you manipulate c?

Alsvha
July 27th, 2006, 11:32 AM
I think Fishdawg65 is on the right track.

Each time you click a asp.net button on an asp.net page, you are making a post-back, meaning the form resubmits to the server to be able to handle said event.
So if you in one event (post-back) sets the value of "c", and in another event (post-back) wants "c" to retain its value, then you need to save the content of "c" somewhere to be able to reuse it, otherwise it will be cleared next time you cause an event/resubmit the form.

saimukesh
July 28th, 2006, 12:16 AM
Hi, there was nothing about value "c" in the page load.Infact i am not using pageload event in my project.I heard that we have to declare "c" as session variable.But i dont know how it can be done?In global.asax file i am declared as session("c")=?(what), this is where my problem.Can any one help me pleasse?....

Fishdawg65
July 28th, 2006, 02:04 AM
To declare a session variable in c#:

Session["c"] = fileName;


You can do this at any point in your code. To get the value out then you just use: Session["c"].ToString()

I really doubt you are having a problem with using sessions though if you are using the same page for everything...

saimukesh
July 28th, 2006, 05:15 AM
Thanks the Problem is resolved....