|
Actually, you can embed a Windows Forms UserControl in a web page and it can access the file system (by default in .NET 1.1, using isolated storage), so long as you have the permissions to do so.
See my old article at http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=388[^].
I think he's having problems access a file on the web server from the UserControl which is executed client-side, but I can't really make any sense of his question either.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I can't really make sense of your question either, but let me try...
You're saying that the UserControl you've embedded in a web page uses http://localhost to access a file on the server? IF so, ALL content in a browser window that users see - including embedded .NET, ActiveX, and Java controls - run all on the client machine. So http://localhost refers to their machine, which requires that a web server be running. While "localhost" resolves to the 127.0.0.1 IP address that all machines define as themselves (the loopback address), putting http:// requires that they have an HTTP daemon (like IIS or Apache) running on the default HTTP port, which is port 80. Fat chance that all your clients have that.
So, remember that your embedded user control runs client-side. The only access back to the server is the same as any user would have to make: you need to use the fully-qualified URL of the server. Any file paths you use must also be local to their machine.
Above all, you must grant your user control permissions by getting the users to install a code group on their machines. If they don't, your options are none to limited so program accordingly. In .NET 1.0, controls in the Internet zone were not allowed to execute at all. In .NET 1.1 (partly thanks to yours truly), controls in the Internet zone are granted some permissions, but not many. The only file system access is through isolated storage (System.IO.IsolatedStorage ). So you have to add a code group (do not change the Internet_Zone group!) that grants your assembly/assemblies the necessary permissions based on host or strong name identity evidence (other types of evidence are not collected by IEExec.exe, the managed host for Internet Explorer).
Read my old article, User Controls for Windows and the Web[^], for more details.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi
I have a problem with menu and FormBorderStyle = None:
I opened new C# project and set the property FormBorderStyle = None , And added main menu. When I run the application and on the last pixel of the menu, i have got a line drawn. This line divide the menu and the rest of the form. How can I make the line disappear?
Thanks Rafi
|
|
|
|
|
Can we define constructor with arguments in web service.
So, suppose the Web service.asmx file looks like:
public class Service2 : System.Web.Services.WebService
{
string b = null;
public Service2()
{
InitializeComponent();
}
public Service2(string b1)
{
b = b1;
}
[WebMethod]
public string HelloWorld(string vivs)
{
return vivs+ b;
}
and at client side, I am creating proxy object like:
WebService1.localhost.Service2 obj = new WebService1.localhost.Service2("Hello");
string myname = obj.HelloWorld("vivekagarwal");
Response.Write(myname);
But the problem is, i am getting error while creating object with passing argument ("Hello").
It is saying that we can't pass the argument.(Even when I have created the default constructor with no-argument)
any body has any idea???..becaz my primary function here is..to initialize the object upon creation...
Thanks
-Vivek Agarwal
|
|
|
|
|
Sure you can define such a constructor, but it won't make a difference. The XML Web Service specifications don't describe activation but remote method calls. ASP.NET - having to instantiate the WebService derivative when calls are made - has to instantiate objects because that's how the .NET Framework works. XML-RPC - a predacessor to XML Web Services and there are now WSDL/SOAP-compliant libraries - simply allows you to call methods with an object at all. For that matter, so does XML Web Services.
Object activation is a feature of the hosting framework - not of XML Web Services.
Even when you instantiate your client proxy for the XML Web Service, the object on the server is not created. It is created on the first call to its methods with a particular lifetime. It's when you make calls that any remote calls are made.
In fact, find yourself a packet analyzer (like the widely popular WinPcap with its corresponding Analyer program) and examine the packets after 1) instantiating the client proxy, and 2) calling a method. You'll actually only see one request (assuming data chunking isn't used for that method): for the method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Stewart,
For such a g8 reply.
Regards
-Vivek
|
|
|
|
|
Good morning,
I have a custom (windows) user control, which is my own designer host implementation. It all works fine when I run the control in a windows app. I have toolbox, property window, etc.
However, I require this form to be implemented in a web page. I am using the <OBJECT> tag to achieve this, and the control is displayed correctly. It all works as per the windows app, with one small problem!
In my implementation of IContainer.Add, I call
<br />
IDesigner designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));<br />
This works fine when hosted in the windows app. In the web however, it returns null. ARGH! If I remove the [Designer] attribute from the control, its ok. I've tried specifying the designer type using typeof and as a fully qualified string. Also tried adding the second parameter (BaseDesignerType) as typeof(IDesigner) and that hasn't helped either??
Apologies for the long post its driving me mad!!
Anyone have any ideas?
Thanks in advance,
Simon.
|
|
|
|
|
When you host a control in IE, the playing field changes. First of all, is the designer in the same assembly as your control, or a separate assembly? What membership condition identities your assembly and what permission set is granted to it based on matching evidence? Are you simply using FullTrust?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Thanks for your information.
Yes, the designer is in the same assembly as the control it is designing. This assembly is seperate to the assembly containing the designer host, but as the designer host can 'see' the control, I'm sure it must have access to the designer as well. Both assemblies have full trust (they will only be used on intranet, and security protocols are already in use in other parts of the app, so it's not really a security risk).
I have now resolved this problem. I used Reflector to see what TypeDescriptor.CreateDesigner(IComponent comp, Type designerBaseType) was doing, and copied the code to a local method so I could debug it. If you are interested, the problem appeared to be that Type.GetType(designerBaseType) was returning null. (the designerBaseType parameter was hard-coded to IDesigner).
I got around this problem by changing all the controls (no, users will never add their own controls to this designer!) to use the constructor of the DesignerAttribute that accepts two parameters, and set the second one to the same type as the first. When the component is then added to the design form, I get the DesignerAttribute for that type, and call TypeDescriptor.CreateDesigner with the type specified in the second parameter of the attribute.
OMG I don't really understand what I just wrote! - it you are really interested, feel free to email me and I'll try to explain in more detail!!!
Thanks for your reply.
Simon.
PS: Is Reflector the most AMAZING tool for .NET development?!?!
|
|
|
|
|
|
I don't understand...?
/\ |_ E X E GG
|
|
|
|
|
Hi coders,
Can anybody just give me the idea, how to implement a discussion forum like this.
http://codeproject.com/script/comments/forums.asp?forumid=1649
Regards,
Beenish
|
|
|
|
|
|
Guys,
I'm connecting to different servers using IP/PORT. So far I'm connected to 70 ip/port at the same time using the statement below. My problem is that if i'm using a port which has a value greater than 70000 it gives me an error "index out of bound"
string stripd = "10.32.54.23";<br />
string strport = "70252";<br />
<br />
IPAddress ip = IPAddress.Parse (stripd);<br />
Int32 iPortNo = Convert.ToInt32 ( strport);<br />
IPEndPoint ipEnd = new IPEndPoint(ip.Address, iPortNo);<br />
socketList[arrcnt].Connect (ipEnd);
I think int32 is not enough for the value=70252 but I tried to change it to int64 but the IEndPoint object doesn't accept long datatype.
Kindly help me, I'm got getting any data for that particular PORT.
Thank you very much in advance
/Dabuskol
|
|
|
|
|
THE TCP/IP specification defines the port as a 16 bit integer. That gives a range of 0 to 65535. You cannot define a port outside that range.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
What can I do then I have 5 ports with greater than 70000. Do we have any other object that I can use for this scenario?
Thanks for the help
/Dabuskol
|
|
|
|
|
I don't know how you have any ports greater than 65535 as TCP [The underlying protocol] does not support it. It has nothing to do with the .NET Framework.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Ok. I will check with our administrators why he is sending me these ports. Sorry, I'm new to IP/PORT thing
I thought it's .net problem
/dabsukol
|
|
|
|
|
dabuskol wrote:
I think int32 is not enough for the value=70252
Your question was already answer correctly (TCP doesn't support ports about 65535), but an Int32 - if you read the documentation and if you know anything about bits - is plenty large enough to hold the value 70252.
An Int32 is a signed 32-bit integer that can hold 2^32 bits of data. Because it's signed, it can have a negative value. This value can range from -2,147,483,648 to 2,147,483,647. 70252 easily falls within that range.
As Colin said, this problem has nothing to do with .NET.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Since I received good answers on my previous question I'll go for a new.
I have a richtextbox and like to highlight lines that contain a specific string.
I'v found the .Find method which lets me search for a string and then with the selection methods I can highlight by changing font and foreground colour etc.
But the problem is that only the search string becomes selected and not the whole line. Also only the first occurrence is selected but I guess that's solvable.
Is there some way to achieve this with .Find or is there any other way I can/should go?
|
|
|
|
|
Looking at the richtext control in a prototype project I built, it indicates that display.Find() returns an index of the found line of text.
So it may be possible to make use of the display.GetLineFromCharIndex() using the result form Find();
So your final code would be this:
RichTextBox display = new RichTextBox();
...
public void SetLine(string textToSelect)
{
int locate = display.Find(textToSelect);
int linePos= display.GetLineFromCharIndex(locate);
this.SetSelectedStyle();
display.SelectedText = display.Lines[linePos];
}
The approach I took to determine this was to create a blank project.
Add a richtext control.
Create a dummy method in the project so that I can see exposed properties and methods.
Start looking at 'WHAT' for the return type and description of Find();
See what is exposed that deals with lines based on character position.
See what collection might be used for the output of that.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
OK, I tried that and it worked somehow but there's still a problem.
Given the code below I search for the string "string" and then select the line that contains the string "This is the string I search for". The result will be that string is replaced and highlighted and thus giving:
"This is the This is the string I search for I search for".
I have tried several solutions avoiding this, but I assume I need to use SelectedText.Replace or set Select to start from the beginning of the line
But I can't find out a way to calculate where the line starts and ends.
Anyone that can hint how to proceed?
private void WinForm_Load(object sender, System.EventArgs e)
{
richTextBox1.Text = "Hello world\n";
richTextBox1.AppendText("This is the string I search for\n");
richTextBox1.AppendText("The last row\n");
}
}
private void button1_Click(object sender, System.EventArgs e)
{
int locate = richTextBox1.Find("string");
int line = richTextBox1.GetLineFromCharIndex(locate);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = richTextBox1.Lines[line];
string q = richTextBox1.Lines[line];;
richTextBox1.SelectionProtected = true;
int len = richTextBox1.Lines[line].Length;
string txt = richTextBox1.Lines[line];
richTextBox1.SelectionCharOffset = 5;
richTextBox1.AppendText("Line no: " + line + ", Locate: " + locate + ", Len: " + len + "\n");
richTextBox1.AppendText(txt + "\n");
richTextBox1.AppendText("q: " + q);
}
|
|
|
|
|
Dunno what I was thinking about yesterday since it was pretty obvious.
private void onLoad(object sender, System.EventArgs e)
{
richTextBox1.Text = "Hello World\n";
richTextBox1.AppendText("This is the string I search for\n");
richTextBox1.AppendText("Another Hello World Again\n");
}
private void button1_Click(object sender, System.EventArgs e)
{
int loc = richTextBox1.Find("string");
int linePos= richTextBox1.GetLineFromCharIndex(loc);
int lineLen = richTextBox1.Lines[linePos].Length;
int lineStart = richTextBox1.Lines[linePos].IndexOf("string");
richTextBox1.Select(lineStart,lineLen);
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = richTextBox1.Lines[linePos];
richTextBox1.AppendText("strPos: " + loc + ", Len: " + lineLen + ", linestart: " + lineStart);
}
|
|
|
|
|
I want to access a class (TestClass) that is in a given assembly(Test.dll) on my machine.
I use activator :
ObjectHandle objH=null;
objH=Activator.CreateInstanceFrom(@"\\Daniel\SharedDocs\Test.dll","TestClass");
TestClass tc=(TestClass)objH.Unwrap();
MessageBox.Show(tc.GetCompName());
But I get this error : "Required permissions cannot be acquired."
What should I do?
Thanks,
Daniel.
|
|
|
|
|
You should not load the DLL from a network path... instead use a local copy. Or change the default security settings in "Control Panel".
|
|
|
|