|
I would say that you have no idea how ASP.NET works. Assuming you got the full path to the file on the client's machine, what would you hope to do with it ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Do .txt data to SQL table operation. I'm not doing upload operation, I'm doing insert operation using upload form. The client machine is always the user machine so there's no problem. The following line
its: string[] data = File.ReadAllLines(path);
If there's another (and better) way, please say to me.
|
|
|
|
|
Why are you using pure HTML and not server controls ? Why not use a server control and just grab the file data from the stream you get passed ? Surely you're not saying your application is only ever used by someone who is on the server ? If it's never used over the internet, or a LAN, why use ASP.NET at all ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Old habits...
What I meant to say is that the method I was trying to use works because the file its always on client side, so why not open and read data on client side and write it on server side?
I work on ASP.NET less than 48 hours so I dont know a server control to do that.
By server control you mean something like this: ?
<asp:FileUpload ID="FileUpload1" runat="server" />
What would be the diference?
|
|
|
|
|
Maxdd 7 wrote: so why not open and read data on client side
Because your C# code never runs on the client, it runs on the server.
Maxdd 7 wrote: What would be the diference?
This control has a property that contains the bytes of the file in question.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I followed your advice and done:
caminho = Path.GetFullPath(FileUploadControl.PostedFile.FileName);
and
cam = Path.GetFullPath(FileUploadControl.PostedFile.FileName);
and another tries, and always have same result:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\file.txt (is not even the same hard drive)
I googled about it, and looks like File Upload Control does not allow getting full path of client's machine. They say its a security thing.
|
|
|
|
|
You didn't remotely follow my advice. you CANNOT access the file from the server to the client. The PostedFile property has a property which contains the file contents.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You are right.
I found this.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile.aspx[^]
I've adapted to my program, but having the problem I tought. If I use streams to read the file, I will not have text data.
So I'm trying convert that stream data using:
StreamReader reader = new StreamReader( myStream );
string text = reader.ReadToEnd();
and
byte[] bytes = new byte[myStream.Length];
string data = Encoding.ASCII.GetString(bytes);
But its not working
EDIT:
I did this and its finally working
byte[] bytes = new byte[myStream.Length];
myStream.Position = 0;
myStream.Read(bytes, 0, (int)myStream.Length);
string data = Encoding.ASCII.GetString(bytes);
modified on Thursday, November 12, 2009 1:05 PM
|
|
|
|
|
I worked many time with PHP, and always used Sessions variables. For example: I have two users, with two different access level (lets say admin is 1 user is 2). The webpage as an ordinary table with information. Admin can view and edit, but user can only view.
With PHP what I did is define the access level on a field (SQL table) of the table 'Users', and then, depending on the value of that field I do something like:
index.php (..)
if($_SESSION['level'] == 1)
include(indexAdmin.php)
if($_SESSION['level'] == 2)
include(indexUser.php)
Do you see the point? I need to do something similar with ASP.NET 3.5 C# coding, and I dont want to use and create groups on web.config.
What can I do ?
|
|
|
|
|
The session works somewhat the same, except instead of an include to pull in php code, you would actually write code to show the menu items you want to show.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
So I work on .aspx or on .aspx.cs?
|
|
|
|
|
Depends. As someone else said, one possible way is to put items in panels in the aspx, and then show/hide them in the .cs file. If you were building a menu, I'd put it in a master page, and the items for that could well be added entirely in the cs file. It depends on what the specifics are of your task.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I have a GridView, with Insert, Delete and Edit options, (on TemplateFields) so I dont want these operations available for all users... how can I do that?
|
|
|
|
|
I am not sure, you'll have to experiment. Those options go in the aspx usually, I'd try to see if they can be added in code, so you can do it conditionally.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You put the "me.textbox1.readonly=true" in the .aspx.cs.
(I'm not sure of the C# syntax, my code behind is in VB)
|
|
|
|
|
If you are now developing an ASP.NET page, you can set the controls property, READONLY, to either true or false depending on the user's security.
For example:
If (user is admin) then
Me.Textbox1.Readonly = False
else
Me.Textbox1.Readonly = True
end if
The other thing you can do is group the fields on a page inside a "Panel" and set it's Visible property to True/False. This will effectively remove the fields from the page.
david
|
|
|
|
|
The problem is I have a GridView, with Insert, Delete and Edit options, (on TemplateFields) so I dont want these operations available for all users... just that.
|
|
|
|
|
Hi,
You can use this (as David above mentioned):
<asp:Panel runat="server" ID="pnlAdmin">
… my admin section
</asp:Panel>
<asp:Panel runat="server" ID="pnlUser">
… my common user section
</asp:Panel>
If (user is admin)
pnlAdmin.Visible = true;
else if (user is user) {
pnlUser.Visible = true;
pnlAdmin.Visible = false;
}
It’s easy but it’s not so excellent. Consider to read this article to get more info: http://ryangaraygay.com/blog/post/2008/04/PlaceHolder-and-Panel-Visibility-and-ViewState.aspx[^]
Petr Pechovic
|
|
|
|
|
Thank you very much to all
Thanks for your pacience, I'm iniciating ASP.NET and there's a lot of things to learn so sometimes I know I could be a little so please be pacience, I'm trying.
|
|
|
|
|
I have to load .txt data to sql table. Im doing this:
string path = "E:\\fich.txt";
string query;
query = "LOAD DATA INFILE '" + path + "'";
query += " INTO TABLE Filmes";
SqlCommand com = new SqlCommand(query, Conn);
string q;
q = (string)com.ExecuteScalar();
But getting error: incorrect syntax near E:\fich.txt
Any ideas? What am I doing wrong?
modified on Wednesday, November 11, 2009 3:43 PM
|
|
|
|
|
Maxdd 7 wrote: StreamReader sr = File.OpenText("E:\\fich.txt");
Why would you open the file in a stream that you never use ? I'd suspect that is locking the file. Unless the file contains single quotes ( which you can fix with a string.Replace call ), I'd be more inclined to use File.ReadAllText and just do a normal insert of that text.
Are you sure that execute scalar would return a string in this instance ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Ups, I forgot to delete that line in this post.
I really would like to use Load Data Infile, just have sintax problems, cant you help me?
|
|
|
|
|
Did you try without that line and still got the error ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Yes.
Still having incorrect syntax near 'e:\fich.txt'
|
|
|
|
|
I am reading the books online, where are you getting the documentation that makes you think this will work at all ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|