|
i have the path of a file in a string variable. i am reading that using the following code
new FileStream(path, FileMode.Open, FileAccess.Read);
it's working fine when i execute from local machine .when i upload it into server it is showing the error 'Could not find a part of the file..
Any one can help me.........
Anu
|
|
|
|
|
try this code
new FileStream(Server.MapPath(path), FileMode.Open, FileAccess.Read);
Best Regard
Pathan
---------------------------------------------------
|
|
|
|
|
Then it'is coming like this
'D:\Anu\Pic1.bmp' is not a valid virtual path.
|
|
|
|
|
You can't read a file that doesn't exist.
Put the file that you want to read on the server. Put the virtual path to the file in the path variable, and use Server.MapPath(path) to get the physical path to the file.
---
single minded; short sighted; long gone;
|
|
|
|
|
i didn't understand.can you give me a sample code?..
|
|
|
|
|
How can i put the file into the server using path. if i am using file upload control then i can use fileuploadcontrolname.postedfile.saveas(server.mapath(filename)).but i am not using that control.i am only have the path of the file in a string variable...How can i do.......
Anu
|
|
|
|
|
You can't do that directly SO you want to read the Uploaded file
then use fileuploadID.PostedFile.InputStream as input to Stream reader and read the file
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
anujose wrote: i didn't understand.can you give me a sample code?..
The example code will be exactly as Pathan showed:
new FileStream(Server.MapPath(path), FileMode.Open, FileAccess.Read);
The path in the path variable should be a virtual path, like for example "/SomeFolder/SomeFile.txt" .
---
single minded; short sighted; long gone;
|
|
|
|
|
Guffa was right and I just submit his answer with simple code
FileInfo fInfo = new FileInfo(fudoc.Value.ToString());
fudoc.PostedFile.SaveAs(Server.MapPath("~/UplDoc/") + fInfo.Name);
after this read file from Folder UplDoc
FileInfo fi = new FileInfo(Server.MapPath("~/UplDoc/filename.extension"));
Hope it helped
I Love SQL
|
|
|
|
|
i think no need to save also give one of the steamreader parameter as uploadfileCntrolID.Postedfile.InputStream
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
It was my quick answer
Addition in my previous post: After the job is done with file then file can be deleted
FileInfo fdelete = new FileInfo(Server.MapPath("~/UplDoc/filename.extension"));<br />
fdelete.Delete();
I Love SQL
|
|
|
|
|
Hi All!
in my application, there is a table tblCountries(countryId,countryName) & i have a class: person
public class Person
{
private string name;
private int countryID;
public string Name
{
get {return this.name;}
set {this.name = value;}
}
public string CountryId
{
get {return this.countryID;}
set {this.countryID= value;}
}
}
now i want to add an property CountryName which returns name of the country name rather than country . can any one help me in this regards?
|
|
|
|
|
Smells like homework, but...
Check out DataTable.Select.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
I have a transaction that adds sql statements between postbacks that occur at specific button clicks. And the transaction is finally commited at another button click.
Each time the postback occurs the sql commands are added to the transaction without any problem but finally when i commit it, an exception occurs that says:
"This SqlTransaction is completed; it is no longer usable."
When I viewed the property of the transaction object while debugging I ve noticed a Timeout property that has the value 15. I dont know whether it is in seconds or minutes. I think it is due to the timeout the transaction is gettting completed.
I have declared the transaction globally in my page say "MemberLinking.aspx" as:
<br />
Private Shared myTrans As SqlTransaction<br />
I have then passed the transaction to a function defined in a class file like this:
<br />
Public Sub BeginTransaction(ByRef tsql As SqlTransaction)<br />
Try<br />
tsql = conn.BeginTransaction()<br />
Catch ex As Exception<br />
Finally<br />
End Try<br />
End Sub<br />
This function begins the transaction. The other functions that adds the commands to the transaction are also passed the transaction as parameter. Vut it is done by value.
I have added the sql statements to the transaction as:
<br />
sqlstatement = "UPDATE UserFamily SET UserID=" & LinkedUID & " WHERE UserID=" & UID & " AND FamilyID=" & FID<br />
cmd = ReturnSqlCommand(sqlstatement)<br />
cmd.Transaction = Mytrans<br />
cmd.ExecuteNonQuery()<br />
<br />
sqlstatement = "INSERT INTO UserFamily(UserID,FamilyID,Accepted,IsModerator) VALUES (" & ChildID & "," & FamilyID & _<br />
",1,0)"<br />
cmd = ReturnSqlCommand(sqlstatement)<br />
cmd.Transaction = Mytrans<br />
cmd.ExecuteNonQuery()<br />
where ReturnSqlCommand() is a function that takes as string a parameter and returns it as an SqlCommand object. The above two are not the only statements. The application adds a set of statements at each postbacks. Through out this process there is no error or exception utill i try to commit or rollback the transaction object.
|
|
|
|
|
AFAIK: Everytime you postback, your page and all it's code behind variables are recreated and reinitialized, but controls retain their values because of the magical viewstate.
SqlTransaction doesn't have any concept of viewstate, so it's a fresh new SqlTransaction each time.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Thank you Steve
Is it anyway possible to preserve the transaction b/w postbacks? Is there any chance of transaction getting timed out?
|
|
|
|
|
Hello,
In my internet site, i have to proivde search functionality within the website domain. Could you please give some light where should i look for related articles,sample code, ideas etc....
Thanks,
Thanks
|
|
|
|
|
|
I have a string
bobby@yahoo.com (Bobby Gill)
I want to parse it and want to get the substring "bobby@yahoo.com" before space.
Could you please give me code.
thanks
seema
|
|
|
|
|
I didn't quite understand what you want. Can you explain a bit more
|
|
|
|
|
string s="bobby@yahoo.com (Bobby Gill)"<br />
int indx=s.IndexOf(' ');<br />
string val=s.Substring(0,indx);
OR
string s="bobby@yahoo.com (Bobby Gill)"<br />
string[] ss=s.Split(' ');<br />
int count=0;<br />
string val;<br />
foreach(string s1 in ss)<br />
{<br />
if(count==0)<br />
{<br />
val=s1;<br />
}<br />
count=1;<br />
}
Best Regard
Pathan
---------------------------------------------------
|
|
|
|
|
Hi all,
I'm trying to make an asp.net data entry table work like they do in access. what i want is a one line table with 3 columns (a time picker, a drop down, and a comments section). When the line is fully populated, I'd like a new empty line to appear below so the user can continue to add any number of lines.
I can't figure out any easy way to do this, and that usually means i'm missing something simple any help is greatly appreciated!
thanks in advance,
Craig
|
|
|
|
|
try repeater control or datagrid and add template columns
Shujaat
|
|
|
|
|
have a AutoCompleteExtender and I bound it to a textbox. It is the list of
all email address and last name and first name
nMultani@dov.gc.ca (nancy Multani)
bGill@dov.gc.ca (babay Gill)
I want to validate this text box. I want to create new validation control
the text box I type only that item which appear in drop down list or select
valid item or type whole string.
How can I do that.
seema
|
|
|
|
|
I have a gridview that, depending on the information being passed to it, needs to flag the Visible attribute of a textbox control in one of the template columns. so here is a quick snippet of the datarow as it is being built:
dr[4] = "";
dr[5] = s;
dr[6] = "false";
the datatable columns it references:
dt.Columns.Add("filler");
dt.Columns.Add("key");
dt.Columns.Add("Vis");
and the line in the gridview that is having issues:
<asp:TextBox ID="txtItmQty" runat="server" Text='<%# Bind("filler") %>' Width="42px" Visible='<%# Bind("Vis") %>'></asp:TextBox>
every time i run it, i get this:
<b>Specified cast is not valid.</b>
how or what do i have to pass to the Visible attribute to set this dynamically?
-- modified at 18:14 Thursday 13th September, 2007
______________________
Mr Griffin, eleventy billion is not a number...
-- modified at 18:14 Thursday 13th September, 2007
|
|
|
|