This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have a method with a Stream for input :
public void Export(Stream finalOutPutStream)
For test purposes, i call it with a memory stream, like this :
// When
_exporter.Export(new System.IO.MemoryStream());
But when, in the method, i want to write on this memory stream, i get a ObjectDisposedException.
This stream is not enclosed in a using statement, i do not call explicitely .Dispose().
What happened ?
Thanks :)
--
EDIT : my bad, the problem is from the third party writer (DotNetZip). The exception happens when i call zip.Save(new MemoryStream()). I will ask my questions on their forum.
Sorry, and thanks for the help.
You can check stream availability using: CanRead, CanSeek, CanWrite properties.
if you put the stream creation inside using it will do the closing and resource release for you
EX:
using(Stream s = new MemoryStream())
{
// do your operations
}
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
To cut to the chase, when performing some calculations within my code i have a result that is something like. 7.6742332E-30, i have this value stored in a double variable for example, double result = 7.6742332E-30;
When i later check whether this value is greater than 0 the result is true, that it is greater than 0, i assume due to the 7.6742332.
So my question is this, why is the E-30 not being considered and how do i resolve this?
Any advice would be great and thanks so much i advance!
7.6742332E-30 is 0.0000000000000000000000000000076742332, which is a positive number.
7.6742332E-30 mathematcally equals 7.6742332 x 10^-30 which is a positive number
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
not much to explain as I have no logical explaination as to why this is not working :s
Just to confirm, It is a 'jpeg' file extention, the name is correct and I don't see any other issue with why it would not work be found.
You're saving it to a filename ending with "jpg" and then loading from a filename ending with "jpeg". Assuming you're trying to load the file you've just saved, that's the problem.
(I'd copy the code to point out the lines in question, but you only included it as an image...)
I'd strongly suggest constructing the filename once, and using that variable twice:
// I prefer using Path.Combine over string concatenation, but both will work.
// You might want to change "Identitys" to "Identities" though :)
string file = Path.Combine(#"C:\", "SimpleSkype", "Identitys", dd + ".jpg");
SaveSkypeAvatarToDisk(u.Handle, file);
using (Image image = Image.FromFile(file))
{
...
}
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Im struggling to get the right syntax to use in c# for the vb function FormatNumber...i will say that 'iPremium' is an object as it returns data from a tableadapter.
the value that 'ipremium' holds is 943.4000 and the idea is to only have two decimal places after the '.', i would hope this is acheivable using the right syntax but unfortunately not being a c# expert, it could take a while to figure this out.
here's the vb code:
iPremium = FormatNumber(iPremium, 2, TriState.True)
any idea's on how this is acheivable?
thanks for any idea's and suggestions and excuse the ignorance if this is not worded correctly
var formattedNumber = iPremium.ToString("0.00");
or, if you wish to round the number, instead of just chopping-off precision:
var formattedNumber = Math.Round(iPremium, 2).ToString("0.00").Dump();
Here's a list of the various formats you can use with ToString: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
var roundedNumber = Math.Round(iPremium, 2);
var formattedNumber = String.Format("{0:#.##}", roundedNumber);
I assume the TableAdapter returns a Datatable which can also be used strongly typed:
// first row as example (add using.System.Linq)
double value = table.AsEnumerable().First().Field<double>("iPremium");
Now you can use String.Format or just ToString with a custom format:
string result = value.ToString("0.00");
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I'm porting a c++ class to C# and i have a difficulty.
I would like to find an equivalent of SpanIncluding.
Here is my cpp code :
while (Notes.Mid(j,1).SpanIncluding("0123456789").IsEmpty()!=NULL){}
Anyone can help me please ?
I believe SpanIncluding starts matching from the start of the string, stopping when the first non-matching character is found.
So one formulation in the general case would be this:
string match = new string(someString.ToCharArray().
TakeWhile(c => "0123456789".Contains(c)).ToArray());
(or an equivalent using a regular expression).
However, in the example given in the question there's only one character so the whole thing probably boils down to a test of whether this character is >= '0' and <= '9':
while(char.IsDigit(Notes[j])) { ... };
I found the MSDN page for SpanIncluding, and it seems like a ridiculously specific function. I can't really understand what it tries to solve, since it has some strange caveats.
LINQ would be one way of implementing it:
string text = "2334562";
IEnumerable<char> spannedChars = text.TakeWhile(c => "1234567890".Contains(c));
This is a more direct port of SpanIncluding than queen3's option, if I understand the MSDN page correctly, because the result set should stop the minute it hits a character not in the spanning string.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have this piece of coding which is supposed to receive a URL as a string and this URL is supposed to be set as the Image Url :-
Heres the code
foreach (SPListItem item in oSpListCln)
{
if (item.Title.Equals("Rubicks"))
{
Title.Text = item.Title;
lblSyp.Text = item["Sypnosis"].ToString();
PicPic.ImageUrl = item["PicPic"].ToString();
}
}
The value of item["PicPic"] is http://www.froot.nl/wp-content/uploads/quick-brown-fox-froot.jpg,http://www.froot.nl/wp-content/uploads/quick-brown-fox-froot.jpg
This doesn't work is it cause I'm setting a string as a URL of an image cause when I hard coded the link it worked but when I set the link to a string and try, it doesn't. Does anyone know a way of how to do this?
Given that the returned string is comma-separated as you wrote in comments, you could do something like:
string[] urlParts = item["PicPic"].ToString().Split(',');
PicPic.ImageUrl = urlParts[0];