|
You can download web pages using the HttpWebRequest and HttpWebResponse classes. My CP Vanity[^] article holds an example in its downloadPage() method.
|
|
|
|
|
hi,
thanks for your reply,
this is my code, till the content it returns fine but does not save the file in the drive.
how do i make it to save it on the hard disk.
thanks
rssDoc = new XmlDocument();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(value);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
string content = reader.ReadToEnd();
rssDoc.LoadXml(content);
rssDoc.Save("c:asp.xml");
|
|
|
|
|
Hi,
two comments:
1.
aforaries wrote: rssDoc.Save("c:asp.xml");
this is not correct; it needs a backslash after the colon, either insert two backslashes (as one will be ascaped) or use the @ sign:
rssDoc.Save(@"c:\asp.xml");
Furthermore, the top folder of the main partition isn't writable on modern Windows versions (Vista, 7).
2.
content contains the string you received; the easiest way to save that to a file is by using
File.WriteAllText(filespec, content);
That is also the way that assumes content is text, no more, no less; it does not require it to be valid XML; your way of doing things does require valid XML, otherwise rssDoc.LoadXml(content); will fail.
|
|
|
|
|
Hello everybody,
I develop a GMAO csharp smart device application using Visual studio 2008.I try to show my data stocked in my tables in my database .sdf.I use DataGridView tool.I add in the proprietes of my dataGridView the table i wanna show its data.My DataGridViewForm's code is:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ModeDifféré
{
public partial class DataGridT : Form
{
public DataGridT()
{
InitializeComponent();
}
private void DataGridT_Load(object sender, EventArgs e)
{
this.travauxTableAdapter.Fill(this.baseGmaoLocaleDataSet2.Travaux);
}
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
}
}
}
But the problem is when running,an error occurs :
<pre>The column name is not valid. [ Node name (if any) = ,Column name = Effectué/Non ]
what is the problem?
Any help will be very helpful
Regards
|
|
|
|
|
We only see the partial class, so we don't see the generated code, but based on your error message, I'd revisit my column names: your column appears with two special characters : é (e accent aigu) and / (slash). Try renaming your column to something less international (Start with a letter + A combination of letters, digits and _ (underscore).)
|
|
|
|
|
Is there a way to assign a variable a series of values?
What I mean is the first time it is called it's value is 5, the second time its 9, third time its 46, fourth 152 etc
|
|
|
|
|
Well, I guess you could call it an array, or a dictionary.
Your question is vague.
A variable in and of itself won't change it's value on its own.
Are you by chance looking for a randomly generated value, or is there a pattern of numbers you want to return?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Preset values, seemingly random but not actually random.
I think an array would probably be the way to go.
|
|
|
|
|
Wogboiii wrote: I think an array would probably be the way to go.
Not on its own, but most of the generic collections wrap an array.
|
|
|
|
|
You might try some sort of enumerator instead.
Or a Stack or a Queue.
public static class MySeries
{
private static readonly System.Collections.Generic.Queue<int> values ;
static MySeries
(
)
{
values = new System.Collections.Generic.Queue<int>
(
new int [] { 5 , 9 , 46 , 152 }
) ;
return ;
}
public static int
Next
{
get
{
return ( values.Dequeue() ) ;
}
}
}
System.Console.WriteLine ( MySeries.Next ) ;
modified on Sunday, April 25, 2010 11:57 AM
|
|
|
|
|
I don't think that would work because it needs to be assigned the value then that value is used in other functions then the next time it's called its value gets changed.
|
|
|
|
|
|
You can get what you need with generic programming and OOP.
This is a raw example:
public class MultiVar<T>
{
private List<T> Values = new List<T>();
private int ValuePointer = -1;
public MultiVar()
{
}
public MultiVar(T FirstValue)
{
Values.Add(FirstValue);
}
public void AddValue(T Value)
{
Values.Add(Value);
}
public T GetValue()
{
if (Values.Count < 1) throw new ApplicationException("Empty value set.");
if (++ValuePointer >= Values.Count) ValuePointer = 0;
return Values[ValuePointer];
}
public static implicit operator T(MultiVar<T> Object)
{
return Object.GetValue();
}
}
You can check it with:
MultiVar<int> mymultivar = new MultiVar<int>();
for (int i = 10; i < 110; i += 10) mymultivar.AddValue(i);
for (int i = 0; i < 15; i++)
{
Console.Write(" ");
Console.Write((int)mymultivar);
}
Console.WriteLine();
The result is:
10 20 30 40 50 60 70 80 90 100 10 20 30 40 50
Just add code to remove values, if you need it, and customize as needed.
Enjoy!
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
So.. your implicit cast operator has side effects
|
|
|
|
|
And might throw an Exception.
|
|
|
|
|
Yes, and this is perfectly ok too!
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Yes, and this is perfectly ok.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Well I'm going to disagree, but let's see what other people think..
Just because it works does not mean it's ok - this is IMO worse than a getter of a property with side effects. A "funny hack" in this case, but still.
|
|
|
|
|
It's not that I disagree with you, I see your point.
All I'm saying is IMO what I suggested was a good starting point for working out a real world solution for the proposed problem.
He can decide if he likes/wants operator overloading and exception throwing, or he can just use GetValue() (which btw is what I would do in a real world project).
My point is, I just wanted to give him all the possible approaches I could think of to solve his problem.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
At least make it explicit.
"
However, because implicit conversions do not require programmers to explicitly cast from one type to the other, care must be taken to prevent unexpected results. In general, implicit conversion operators should never throw exceptions and never lose information so that they can be used safely without the programmer's awareness. If a conversion operator cannot meet those criteria, it should be marked explicit. For more information, see Using Conversion Operators.
"
I would, however, agree that as long as the behaviour is well documented, it may be accepable within a limited scope.
On the other hand, there are better solutions in this case.
|
|
|
|
|
PIEBALDconsult wrote: would, however, agree that as long as the behaviour is well documented, it may be accepable within a limited scope.
Exactly my point.
PIEBALDconsult wrote: In general, implicit conversion operators should never throw exceptions and never lose information so that they can be used safely without the programmer's awareness.
And thanks for pointing that out explicitly while I didn't.
You are absolutely right on that being important ofc!
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
You don't "call" a variable, so you probably need either a method or a property. Put the code to return the correct value inside the method or property.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Wogboiii wrote: Is there a way to assign a variable a series of values?
Use a collection.
|
|
|
|
|
Yes, if you make the variable a property of a (static) class that provides the behavior you want.
Console.WriteLine (Variable.Value.ToString());
Console.WriteLine (Variable.Value.ToString());
Console.WriteLine (Variable.Value.ToString());
Console.WriteLine (Variable.Value.ToString());
will print
5
9
46
152
/ravi
|
|
|
|
|
Somewhere in the Microsoft guidelines it sure is stated one should not use properties to return changing data; properties should be pretty constant, such as Environment.NewLine . One of the wildest but acceptable exceptions being DateTime.Now .
When real data is to be offered, a method should be used; that is why Directory.GetFiles() and Random.Next() are methods and not properties.
|
|
|
|