Saturday, March 24, 2012
TabStrip in User Web Control
create a menu navigation system for my ASP.NET
application. The menu never changes, so I have every page
in the app using the .ascx control. I have the TabStrip
set up, and it calls the pages correctly. However, I
can't figure out how to change the SelectedIndex when the
page loads.
For instance, the application loads with Tab0 as the
default. When I click on Tab1, Response.Redirect takes me
to the appropriate page, but Tab0 is still selected. I
need to be able to programatically change the
SelectedIndex as the page loads, based on what tab was
selected on the previous page. How can I do that? Thanks.
FlynnCheck out this article,
http://msdn.microsoft.com/msdnmag/i...ge/default.aspx
--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com
"Flynn Arrowstarr" <flynnarrowstarr@.nowhere.net> wrote in message
news:000601c3b43f$a9c27a60$a401280a@.phx.gbl...
> I am using a TabStrip control in a .ascx file so I can
> create a menu navigation system for my ASP.NET
> application. The menu never changes, so I have every page
> in the app using the .ascx control. I have the TabStrip
> set up, and it calls the pages correctly. However, I
> can't figure out how to change the SelectedIndex when the
> page loads.
> For instance, the application loads with Tab0 as the
> default. When I click on Tab1, Response.Redirect takes me
> to the appropriate page, but Tab0 is still selected. I
> need to be able to programatically change the
> SelectedIndex as the page loads, based on what tab was
> selected on the previous page. How can I do that? Thanks.
> Flynn
Thursday, March 22, 2012
Tags inside value field of appsettings in web.config
it looks likes this
<configuration>
<appSettings>
<add key="MyXmlData" value="<data><type></type>......." />
</appSettings>
</configuration
but i get an error message
some one help meYou need to encode/escape the characters. You can do it manually if you
know all of the rules, but I wrote a little utility for myself that I
know will do it right. I guess I should post the full app at some point,
but the relevant method is:
public string Encode(string input)
{
StringBuilder output = new StringBuilder();
using (StringWriter stringWriter = new StringWriter(output,
CultureInfo.InvariantCulture))
{
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartElement("element");
xmlWriter.WriteAttributeString("attribute", input);
xmlWriter.WriteEndElement();
xmlWriter.Close();
}
return output.ToString();
}
Just create a simple WinForms app with a textbox to past a value into, a
button that runs the Encode method, and then a textbox for the output
(not label - you want to be able to select the output for copy/paste).
Joshua Flanagan
http://flimflan.com/blog
Tags inside value field of appsettings in web.config
it looks likes this
<configuration>
<appSettings>
<add key="MyXmlData" value="<data><type></type>......." />
</appSettings>
</configuration>
but i get an error message
some one help meYou need to encode/escape the characters. You can do it manually if you
know all of the rules, but I wrote a little utility for myself that I
know will do it right. I guess I should post the full app at some point,
but the relevant method is:
public string Encode(string input)
{
StringBuilder output = new StringBuilder();
using (StringWriter stringWriter = new StringWriter(output,
CultureInfo.InvariantCulture))
{
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartElement("element");
xmlWriter.WriteAttributeString("attribute", input);
xmlWriter.WriteEndElement();
xmlWriter.Close();
}
return output.ToString();
}
Just create a simple WinForms app with a textbox to past a value into, a
button that runs the Encode method, and then a textbox for the output
(not label - you want to be able to select the output for copy/paste).
Joshua Flanagan
http://flimflan.com/blog
taking a file stream and posting it to a web page
I am getting a stream that contains a PDF file and the task is to get that to a browser for the users. I was able to write code to do this with small files, but there are files so big that it can't be stored in the byte array. I wrote a loop to break down the byte array and it comes accross about the right file size, but Adobe Acrobat can't read it and says it's corrupt. I am thinking there must be a way to write the stream directly into the browser. Why do I need to build a byte array to do things like this (all the examples I find use a byte array)? Is there a way to take the stream and just run it directly into the browser?
Here is the code I have. Works as long as the file doesn't exceed the limits of the byte array:
ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load
'This returns the stream fine:
Dim msAs Stream = Test3A()
'Show the file on the web page
Dim bytByteStream()AsByte
ms.Seek(0, SeekOrigin.Begin)
ReDim bytByteStream(CType(ms.Length,Integer) - 1)
ms.Read(bytByteStream, 0,CInt(ms.Length))
Dim countAsInteger = 0
While count < ms.Length
bytByteStream(count) = Convert.ToByte(ms.ReadByte())
'bytByteStream(count) = ms.ReadByte()
count += 1
EndWhile
Dim brAs BinaryReader =New BinaryReader(ms)
Response.AddHeader("Content-Type","application/pdf")
Response.AddHeader("Content-Disposition","inline;filename=def.pdf")
Response.BinaryWrite(bytByteStream)
EndSub
Here is the same code with the do loop to break it down (but returns a file to the browser that Adobe Acrobat can't read: PublicSub test3c(ByVal msAs Stream) 'Show the file on the web page Dim bytByteStream()AsByte Dim intByteIndexAsInteger Response.AddHeader("Content-Type","application/pdf") Response.AddHeader("Content-Disposition","inline;filename=def.pdf") IfCType(ms.Length,Integer) > 65000Then intByteIndex = 65000 Else intByteIndex =CType(ms.Length,Integer) EndIf ms.Seek(0, SeekOrigin.Begin) ReDim bytByteStream(intByteIndex - 1) 'ms.Read(bytByteStream, 0, CInt(ms.Length)) Dim countAsInteger = 0 Dim intPlaceAsInteger = 0 Dim intCyclesAsInteger = 0 While count < ms.Length bytByteStream(intPlace) = Convert.ToByte(ms.ReadByte()) count += 1 intPlace += 1 If intPlace = 65000Then Response.BinaryWrite(bytByteStream)'Writes to the browser intCycles += 1 'Increse the cycle meter IfCType(ms.Length,Integer) - (intCycles * 65000) > 65000Then ReDim bytByteStream(65000)'If we have more than 65K more to go, set up for next chunk Else ReDim bytByteStream(CType(ms.Length,Integer) - (intCycles * 65000))'If less than 65K, then put out whatever we have left EndIf intPlace = 0 'Reset the index placment counter EndIf EndWhile Response.BinaryWrite(bytByteStream)
EndSub
MemoryStream outputStream = ' Construct the stream here...
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.AppendHeader("content-disposition", "inline; filename=PDFFile.PDF")
Response.BinaryWrite(outputStream.ToArray())
outputStream.Close()
Response.End()
NC...
NC,
I see what you are going for and it would be great if it could be simple like what you are doing. However, I am getting a 'stream' from an API which I am passing to the procedure we are working on. Standard 'stream' does not have a "ToArray()" method. Is there a way to convert the stream to a memoryStream? Is there a way around this?
Schu
Try this then:
Dim ms As Stream = Test3A()
Dim outputStream As MemoryStream = CType(ms, MemoryStream)
' Rest of code...
NC...
I get the following error:
Unable to cast object of type 'EMC.Centera.BlobStreams.BlobReadStream' to type 'System.IO.MemoryStream'.
It allowed me to pull it out into a byte array as shown in my earlier code, any other ideas on what would work?
Schu
I have no idea what an 'EMC.Centera.BlobStreams.BlobReadStream' is. I tried the cast with a normal Stream object with no problem, so no, I have no idea.
Did you try:
Dim ms As MemoryStream = Test3A()
NC...
Yes, I know, that is from the API. They claim it is coming out as a simple stream (but obviously if it were we wouldn't have issues). I rewrote the code assumeing it was a memorystream and got the error:
Specified argument was out of the range of valid values.
Parameter name: offset
when I got to the "...(outputStream.ToArray()). Any thoughts?
I was looking through the documentation for this vendor code (sparse) and they mention that the stream is a "blobstream". then it says "that is what your VB code will use to Read - the Stream.Read method."
So, is there a way to convert a blob stream into a memorystream?
Schu
Well, since I have no access to the API that you are using, and all the references to "BlobStream" seem to be Java API related, who can tell? I'd request help from the vendor that created the API as I don't think that you will get much help here.
You know, if you could write the BlobStream thing to a temporary file, this would work:
Dim fileName As String = Server.MapPath("~\Reports\TestPdfFile.pdf")
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile(fileName)
Response.Flush()
Response.Close()
NC...
Yea, that's a good idea too. Late last night I got together with a couple of the sr devs here and we came up with the following solution that seems to be working. I rem'd out the code that I had in the earlier post so you can see that all I did was remove a section. Thanks for your help! :)
'Show the file on the web pageDim bytByteStream()AsByte
'ms.Seek(0, SeekOrigin.Begin) ReDim bytByteStream(CType(ms.Length,Integer) - 1) ms.Read(bytByteStream, 0,CInt(ms.Length)) 'Dim count As Integer = 0 'While count < ms.Length ' '>>Following line produces error: ' ' "Value was either too large or too small for an unsigned byte." ' bytByteStream(count) = Convert.ToByte(ms.ReadByte()) ' '>>also tried this which did not work ' ' "Arithmetic operation resulted in an overflow." ' 'bytByteStream(count) = ms.ReadByte() ' count += 1 'End While Response.AddHeader("Content-Type","application/pdf") Response.AddHeader("Content-Disposition","inline;filename=def.pdf")Response.BinaryWrite(bytByteStream)
Well, I was wondering why you seemed to be filling the Byte array and then refilling it in the loop, but I guess I got side-tracked on the MemoryStream thing. Glad you got it.
NC...
Tuesday, March 13, 2012
Targeting an <IFRAME> in code
I manage to open a PDF file in an <IFRAME> by "clicking" on an HyperLink
with:
HyperLink.NavigateURL = "file:///C:\file.pdf"
HyperLink.Target = "iframename"
The question is... How can I do the same thing by "clicking" on a
button'
I searched in the System.Web.UI.HtmlControls collection and I can't find
the IFRAME object...
Any ideas?
Thanks in advance
CCAn IFRAME is simply HTML in a Page:
<iframe src ="/something.aspx"></iframe>
Add a runat=server to it, and an HtmlGeneric Control behind it, if you want
to manipulate it programmatically.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
<carlos.cruz@.algeco.pt> wrote in message
news:ecdJl6kFEHA.3252@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I manage to open a PDF file in an <IFRAME> by "clicking" on an HyperLink
> with:
> HyperLink.NavigateURL = "file:///C:\file.pdf"
> HyperLink.Target = "iframename"
> The question is... How can I do the same thing by "clicking" on a
> button'
> I searched in the System.Web.UI.HtmlControls collection and I can't find
> the IFRAME object...
> Any ideas?
> Thanks in advance
> CC
Hi,
I'm sorry but I don't undertand what you mean by putting a generic html
control behind the iframe. Could you be more specific?
Thanks
CC
Every Control (that is part of the Page definition) in the Page Template has
a corresponding object declaration in the CodeBehind class. In this case,
you would have to add it yourself. What software are you using to develop
your app?
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
<carlos.cruz@.algeco.pt> wrote in message
news:ub13YbmFEHA.3448@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I'm sorry but I don't undertand what you mean by putting a generic html
> control behind the iframe. Could you be more specific?
> Thanks
> CC
targetSchema gets reset
dataset in its .XSD file in a project I am (still) developing from the
default http://www.tempuri.org to something of mine, i.e. changed the line:
<xs:schema id="DataSetIC"
targetNamespace="http://www.tempuri.org/DataSetIC.xsd"
xmlns:mstns="http://www.tempuri.org/DataSetIC.xsd"
xmlns="http://www.tempuri.org/DataSetIC.xsd" ...>
Now, every time I change the database and ask Visual Studio .NET to
regenerate the dataset, it chucks away my changes and resets to
www.tempuri.org, which then fouls my integrations with the dataset.
Is there any way I can get VS .NET to retain my target namespace change?I too wish someone could explain this annoying problem, along with the
fact that (re)generating dataset for a dataadapter also throws away the
keys I defined in the DataSet
jb wrote:
> Following MS' recommendation, I have changed the targetNamespace of my
> dataset in its .XSD file in a project I am (still) developing from the
> default http://www.tempuri.org to something of mine, i.e. changed the line
:
> <xs:schema id="DataSetIC"
> targetNamespace="http://www.tempuri.org/DataSetIC.xsd"
> xmlns:mstns="http://www.tempuri.org/DataSetIC.xsd"
> xmlns="http://www.tempuri.org/DataSetIC.xsd" ...>
> Now, every time I change the database and ask Visual Studio .NET to
> regenerate the dataset, it chucks away my changes and resets to
> www.tempuri.org, which then fouls my integrations with the dataset.
> Is there any way I can get VS .NET to retain my target namespace change?
>
Uri,
That's very interesting. Because I have another post elsewhere
(http://communities2.microsoft.com/c...rk.aspnet&fltr=)
which is inspired by *just* what you say. I have suddenly noticed that in
the XSD I had manually defined a unique constraint on behalf of a unique (bu
t
not primary) key I had in my SQL and it gets removed when I regenerate.
Isn't that exactly what you're talking about? I'm tryinjg to find an articl
e
which describes precisely whatever it is that the (re-)generator does or doe
s
not do, so that I can take this into account -- any ideas?
"Uri Dor" wrote:
> I too wish someone could explain this annoying problem, along with the
> fact that (re)generating dataset for a dataadapter also throws away the
> keys I defined in the DataSet
> jb wrote:
>
Uri,
That's very interesting. Because I have another post elsewhere
(http://communities2.microsoft.com/c...rk.aspnet&fltr=)
which is inspired by *just* what you say. I have suddenly noticed that in
the XSD I had manually defined a unique constraint on behalf of a unique (bu
t
not primary) key I had in my SQL and it gets removed when I regenerate.
Isn't that exactly what you're talking about? I'm tryinjg to find an articl
e
which describes precisely whatever it is that the (re-)generator does or doe
s
not do, so that I can take this into account -- any ideas?
"Uri Dor" wrote:
> I too wish someone could explain this annoying problem, along with the
> fact that (re)generating dataset for a dataadapter also throws away the
> keys I defined in the DataSet
> jb wrote:
>
I believe we're talking about the same thing. Regarding the article -
haven't seen such an article yet.
jb wrote:
> Uri,
> That's very interesting. Because I have another post elsewhere
> (http://communities2.microsoft.com/c...rk.aspnet&fltr=)
> which is inspired by *just* what you say. I have suddenly noticed that in
> the XSD I had manually defined a unique constraint on behalf of a unique (
but
> not primary) key I had in my SQL and it gets removed when I regenerate.
> Isn't that exactly what you're talking about? I'm tryinjg to find an arti
cle
> which describes precisely whatever it is that the (re-)generator does or d
oes
> not do, so that I can take this into account -- any ideas?
> "Uri Dor" wrote:
>
targetSchema gets reset
dataset in its .XSD file in a project I am (still) developing from the
default http://www.tempuri.org to something of mine, i.e. changed the line:
<xs:schema id="DataSetIC"
targetNamespace="http://www.tempuri.org/DataSetIC.xsd"
xmlns:mstns="http://www.tempuri.org/DataSetIC.xsd"
xmlns="http://www.tempuri.org/DataSetIC.xsd" ...
Now, every time I change the database and ask Visual Studio .NET to
regenerate the dataset, it chucks away my changes and resets to
www.tempuri.org, which then fouls my integrations with the dataset.
Is there any way I can get VS .NET to retain my target namespace change?I too wish someone could explain this annoying problem, along with the
fact that (re)generating dataset for a dataadapter also throws away the
keys I defined in the DataSet
jb wrote:
> Following MS' recommendation, I have changed the targetNamespace of my
> dataset in its .XSD file in a project I am (still) developing from the
> default http://www.tempuri.org to something of mine, i.e. changed the line:
> <xs:schema id="DataSetIC"
> targetNamespace="http://www.tempuri.org/DataSetIC.xsd"
> xmlns:mstns="http://www.tempuri.org/DataSetIC.xsd"
> xmlns="http://www.tempuri.org/DataSetIC.xsd" ...>
> Now, every time I change the database and ask Visual Studio .NET to
> regenerate the dataset, it chucks away my changes and resets to
> www.tempuri.org, which then fouls my integrations with the dataset.
> Is there any way I can get VS .NET to retain my target namespace change?
Uri,
That's very interesting. Because I have another post elsewhere
(http://communities2.microsoft.com/c...rk.aspnet&fltr=)
which is inspired by *just* what you say. I have suddenly noticed that in
the XSD I had manually defined a unique constraint on behalf of a unique (but
not primary) key I had in my SQL and it gets removed when I regenerate.
Isn't that exactly what you're talking about? I'm tryinjg to find an article
which describes precisely whatever it is that the (re-)generator does or does
not do, so that I can take this into account -- any ideas?
"Uri Dor" wrote:
> I too wish someone could explain this annoying problem, along with the
> fact that (re)generating dataset for a dataadapter also throws away the
> keys I defined in the DataSet
> jb wrote:
> > Following MS' recommendation, I have changed the targetNamespace of my
> > dataset in its .XSD file in a project I am (still) developing from the
> > default http://www.tempuri.org to something of mine, i.e. changed the line:
> > <xs:schema id="DataSetIC"
> > targetNamespace="http://www.tempuri.org/DataSetIC.xsd"
> > xmlns:mstns="http://www.tempuri.org/DataSetIC.xsd"
> > xmlns="http://www.tempuri.org/DataSetIC.xsd" ...>
> > Now, every time I change the database and ask Visual Studio .NET to
> > regenerate the dataset, it chucks away my changes and resets to
> > www.tempuri.org, which then fouls my integrations with the dataset.
> > Is there any way I can get VS .NET to retain my target namespace change?
Uri,
That's very interesting. Because I have another post elsewhere
(http://communities2.microsoft.com/c...rk.aspnet&fltr=)
which is inspired by *just* what you say. I have suddenly noticed that in
the XSD I had manually defined a unique constraint on behalf of a unique (but
not primary) key I had in my SQL and it gets removed when I regenerate.
Isn't that exactly what you're talking about? I'm tryinjg to find an article
which describes precisely whatever it is that the (re-)generator does or does
not do, so that I can take this into account -- any ideas?
"Uri Dor" wrote:
> I too wish someone could explain this annoying problem, along with the
> fact that (re)generating dataset for a dataadapter also throws away the
> keys I defined in the DataSet
> jb wrote:
> > Following MS' recommendation, I have changed the targetNamespace of my
> > dataset in its .XSD file in a project I am (still) developing from the
> > default http://www.tempuri.org to something of mine, i.e. changed the line:
> > <xs:schema id="DataSetIC"
> > targetNamespace="http://www.tempuri.org/DataSetIC.xsd"
> > xmlns:mstns="http://www.tempuri.org/DataSetIC.xsd"
> > xmlns="http://www.tempuri.org/DataSetIC.xsd" ...>
> > Now, every time I change the database and ask Visual Studio .NET to
> > regenerate the dataset, it chucks away my changes and resets to
> > www.tempuri.org, which then fouls my integrations with the dataset.
> > Is there any way I can get VS .NET to retain my target namespace change?
I believe we're talking about the same thing. Regarding the article -
haven't seen such an article yet.
jb wrote:
> Uri,
> That's very interesting. Because I have another post elsewhere
> (http://communities2.microsoft.com/c...rk.aspnet&fltr=)
> which is inspired by *just* what you say. I have suddenly noticed that in
> the XSD I had manually defined a unique constraint on behalf of a unique (but
> not primary) key I had in my SQL and it gets removed when I regenerate.
> Isn't that exactly what you're talking about? I'm tryinjg to find an article
> which describes precisely whatever it is that the (re-)generator does or does
> not do, so that I can take this into account -- any ideas?
> "Uri Dor" wrote:
>
>>I too wish someone could explain this annoying problem, along with the
>>fact that (re)generating dataset for a dataadapter also throws away the
>>keys I defined in the DataSet
>>
>>jb wrote:
>>
>>>Following MS' recommendation, I have changed the targetNamespace of my
>>>dataset in its .XSD file in a project I am (still) developing from the
>>>default http://www.tempuri.org to something of mine, i.e. changed the line:
>>>
>>> <xs:schema id="DataSetIC"
>>>targetNamespace="http://www.tempuri.org/DataSetIC.xsd"
>>>xmlns:mstns="http://www.tempuri.org/DataSetIC.xsd"
>>>xmlns="http://www.tempuri.org/DataSetIC.xsd" ...>
>>>
>>>Now, every time I change the database and ask Visual Studio .NET to
>>>regenerate the dataset, it chucks away my changes and resets to
>>>www.tempuri.org, which then fouls my integrations with the dataset.
>>>
>>>Is there any way I can get VS .NET to retain my target namespace change?
>>>
>>
tcp/ip
number, this is not a web server, it is a file share server. Can anyone poin
t
me to an example on how this works?connect to it for what? But basically you will have to use the standard File
Access ports without some major working.
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:513127E1-F87B-43D9-8F1E-516FF47AA979@.microsoft.com...
>I need to connect to a server via my web page using an IP address and Port
> number, this is not a web server, it is a file share server. Can anyone
> point
> me to an example on how this works?
>
Oh, forgot to add, just add a virtual DIR in the IIS manager to point to
that server\folder, that would be easiest
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:513127E1-F87B-43D9-8F1E-516FF47AA979@.microsoft.com...
>I need to connect to a server via my web page using an IP address and Port
> number, this is not a web server, it is a file share server. Can anyone
> point
> me to an example on how this works?
>
you need to know what protocol the file share server is using.
-- bruce (sqlwork.com)
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:513127E1-F87B-43D9-8F1E-516FF47AA979@.microsoft.com...
| I need to connect to a server via my web page using an IP address and Port
| number, this is not a web server, it is a file share server. Can anyone
point
| me to an example on how this works?
|
tcp/ip
number, this is not a web server, it is a file share server. Can anyone point
me to an example on how this works?connect to it for what? But basically you will have to use the standard File
Access ports without some major working.
--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:513127E1-F87B-43D9-8F1E-516FF47AA979@.microsoft.com...
>I need to connect to a server via my web page using an IP address and Port
> number, this is not a web server, it is a file share server. Can anyone
> point
> me to an example on how this works?
Oh, forgot to add, just add a virtual DIR in the IIS manager to point to
that server\folder, that would be easiest
--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:513127E1-F87B-43D9-8F1E-516FF47AA979@.microsoft.com...
>I need to connect to a server via my web page using an IP address and Port
> number, this is not a web server, it is a file share server. Can anyone
> point
> me to an example on how this works?
you need to know what protocol the file share server is using.
-- bruce (sqlwork.com)
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:513127E1-F87B-43D9-8F1E-516FF47AA979@.microsoft.com...
| I need to connect to a server via my web page using an IP address and Port
| number, this is not a web server, it is a file share server. Can anyone
point
| me to an example on how this works?
|