Dear sir,
I have a word document file contains text and images, now i have saved it as a web page and wants to display it on browser ,
using ,
string str=directory.getfiles("");
response.contentType="text/html";
response .writefile("");
it displayed in different format and images not shown
blank spaces shown as ?????????? and image as X.
i have no. of files stored as word file ,tried to display directly in gridview but it's not posible for me, so i converted them as web page and now i want to display 5 files dynamically in gridview including images., so help me out, looking for ur reply..
, can u tell me how it works, i will be thanxfull to u
i do not want to use web browser or process.start(" IExploreAsassr.exe","path") method because it displays only one file at a time , actually i want to dislay it in gridview item template, including pics.
@shashi shekhar singh
Ok, that wont work, your 1.htm file has to be located on the web server. That way web browsers can down load it using the URL specified as the src attribute.
You can't use a local file path to the 1.htm file...you have to use something like "http://localhost/mywebsite/statichtm/1.htm".
So, place all of the htm files into a folder located within your project. Then loop through the directory and create the URL based on the files you find there.
So you would have something like this to create the URLs: -
string[] getfile = Directory.GetFiles(Server.MapPath("~/statichtm/"), "*.htm");
-
List<string> staticHtmUrls= new List<string>();
-
-
for (int i = 1; i < getfile.Length; i++)
-
{ string staticURL = "/statichtm/"+getfile[i];
-
staticHtmUrls.Add(staticURL );
-
}
So now you have a list of URLs to your static htm files.
I'm thinking that it will probably be easier for you to use a Repeater instead of a GridView.
So your ASP code would look like: -
<asp:Repeater ID="staticWebPagesRepeater" runat="server">
-
<HeaderTemplate>
-
<table border="1">
-
<tr>
-
<td><b>Web Pages</b></td>
-
</tr>
-
</HeaderTemplate>
-
<ItemTemplate>
-
<tr>
-
<td> <iframe src="<%# Container.DataItem %>"></iframe></td>
-
</tr>
-
</ItemTemplate>
-
<FooterTemplate>
-
</table>
-
</FooterTemplate>
-
</asp:Repeater>
And your C# code would have something like this: -
private List<string> _repSource;
-
protected void Page_Load(Object sender, System.EventArgs e)
-
{
-
_repSource = new List<string>();
-
string fileNames[] = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm");
-
foreach (string name in fileNames)
-
{
-
string sp[] = name.Split('\');
-
string urlToStaticHTML = sp(sp.Length - 1);
-
_repSource.Add("/StaticHTM/" + urlToStaticHTML );
-
}
-
staticWebPagesRepeater.DataSource = _repSource.ToArray();
-
staticWebPagesRepeater.DataBind();
-
}
-
23 18994
well, you can use <iframe> tag - <iframe src ="myFilePath.html" width="100%" height="300">
-
<p>iframes not supported</p>
-
</iframe>
in response.write("") pass parameter for showing the iframe tag with the desired file...
cheers,
Nitin
- <html>
-
<head>
-
<meta http-equiv="Content-Type" content="application/doc">
-
</head>
-
<body>
-
<iframe src="your-word-document-file.doc" width="100%" height="100%"> </iframe>
-
</body>
-
</html>
try this.
Hi Shashi,
Have you tired viewing the HTML webpages generated by Word by themselves first?
Make sure that they display correctly before trying to use them in your asp application.
If they are working, consider using IFrames to display the webpages in the grid.
i am really respectfull to u all for ur reply, i want to use like this shown as below, -
-
<div>
-
<iframe id="iframe1" runat="server" scrolling="auto" width="100%" height="100%"> </iframe>
-
-
</div>
-
string[] getfile = Directory.GetFiles(@"D:\Shekhar Documents", "*.htm");
-
for (int i = 1; i < getfile.Length; i++)
-
{
-
HtmlControl frame = (HtmlControl)this.FindControl("iframe1");
-
//string path = Server.MapPath("1.htm");
-
frame.Attributes["src"] = getfile[i];
-
}
i am using this but it not displayed my file content, it only displayed http url.. like "http://www.google.com", please help me out.. i am waiting for ur reply.
try displaying only single file on the page @shashi shekhar singh
Like
frame.Attributes["src"] = getfile[i];
I am giving
frame.Attributes["src"] = "D://shekhardocuments/1.htm";
then it's not displaying , am new for iframe so plzgive me reply.
@shashi shekhar singh
Ok, that wont work, your 1.htm file has to be located on the web server. That way web browsers can down load it using the URL specified as the src attribute.
You can't use a local file path to the 1.htm file...you have to use something like "http://localhost/mywebsite/statichtm/1.htm".
So, place all of the htm files into a folder located within your project. Then loop through the directory and create the URL based on the files you find there.
So you would have something like this to create the URLs: -
string[] getfile = Directory.GetFiles(Server.MapPath("~/statichtm/"), "*.htm");
-
List<string> staticHtmUrls= new List<string>();
-
-
for (int i = 1; i < getfile.Length; i++)
-
{ string staticURL = "/statichtm/"+getfile[i];
-
staticHtmUrls.Add(staticURL );
-
}
So now you have a list of URLs to your static htm files.
I'm thinking that it will probably be easier for you to use a Repeater instead of a GridView.
So your ASP code would look like: -
<asp:Repeater ID="staticWebPagesRepeater" runat="server">
-
<HeaderTemplate>
-
<table border="1">
-
<tr>
-
<td><b>Web Pages</b></td>
-
</tr>
-
</HeaderTemplate>
-
<ItemTemplate>
-
<tr>
-
<td> <iframe src="<%# Container.DataItem %>"></iframe></td>
-
</tr>
-
</ItemTemplate>
-
<FooterTemplate>
-
</table>
-
</FooterTemplate>
-
</asp:Repeater>
And your C# code would have something like this: -
private List<string> _repSource;
-
protected void Page_Load(Object sender, System.EventArgs e)
-
{
-
_repSource = new List<string>();
-
string fileNames[] = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm");
-
foreach (string name in fileNames)
-
{
-
string sp[] = name.Split('\');
-
string urlToStaticHTML = sp(sp.Length - 1);
-
_repSource.Add("/StaticHTM/" + urlToStaticHTML );
-
}
-
staticWebPagesRepeater.DataSource = _repSource.ToArray();
-
staticWebPagesRepeater.DataBind();
-
}
-
Respected Sir @Frinavale
I have used as u have explained by using repeater with iframe and the url , but i am geting error ...
C# Code: -
//string[] getfile = Directory.GetFiles(Server.MapPath("~/statichtm/"), "*.htm");
-
string[] getfile = Directory.GetFiles(@"D:\Shekhar Documents\Tutorial + Development\html\Question_Html","*.htm");
-
List<string> staticHtmUrls = new List<string>();
-
-
for (int i = 1; i < getfile.Length; i++)
-
{
-
string staticURL = "/statichtm/" + getfile[i];
-
staticHtmUrls.Add(staticURL);
-
}
-
staticWebPagesRepeater.DataSource = staticHtmUrls.ToArray();
-
staticWebPagesRepeater.DataBind();
-
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------- -
<asp:Repeater ID="staticWebPagesRepeater" runat="server">
-
<HeaderTemplate>
-
<table border="1">
-
<tr>
-
<td><b>Web Pages</b></td>
-
</tr>
-
</HeaderTemplate>
-
<ItemTemplate>
-
<tr>
-
<td> <iframe src="<%# Container.DataItem %></td>"></iframe></td>
-
</tr>
-
</ItemTemplate>
-
<FooterTemplate>
-
</table>
-
</FooterTemplate>
-
</asp:Repeater>
-
-
</div>
Error is:
Server Error in '/bytes' Application.
--------------------------------------------------------------------------------
HTTP Error 400 - Bad Request.
--------------------------------------------------------------------------------
Version Information: ASP.NET Development Server 9.0.0.0
one thing that i forgot to explain to you. My original source file was of word Document type(MS word 2007) (text + image), i converted them in to .htm file, so when i add all files(.htm+image folders) into Visual Studio Solution Explorer and open to view in browser the error is:
Server Error in '/bytes' Application.
--------------------------------------------------------------------------------
HTTP Error 403 - Forbidden.
--------------------------------------------------------------------------------
Version Information: ASP.NET Development Server 9.0.0.0
looking for your reply it's urgent for me..
Well there are a couple of reasons why this wont work.
I didn't fully test the code because I was just quickly giving you an example and thought that you'd be able to figure it out from there. I work mainly in VB.NET and so I didn't test the loop that you had in your code already...needless to say I did not test the code, it was just an example.
The first problem with the code I posted is that I accidentally left a "<td>" in the src attribute in the ASP code....the ASP code should be: - <asp:Repeater ID="staticWebPagesRepeater" runat="server">
-
<HeaderTemplate>
-
<table border="1">
-
<tr>
-
<td><b>Web Pages</b></td>
-
</tr>
-
</HeaderTemplate>
-
<ItemTemplate>
-
<tr>
-
<td> <iframe src="<%# Container.DataItem %>"></iframe></td>
-
</tr>
-
</ItemTemplate>
-
<FooterTemplate>
-
</table>
-
</FooterTemplate>
-
</asp:Repeater>
The second thing that is wrong with this code is that when you use the Directory.GetFiles() method it returns you a list of Path And File Names that match the pattern you're searching for.
We stated earlier that you cannot have a local path to a file because the web browser will not be able to download it...web browsers cannot access local files on your computer, it can only access files that exist on the web server and can only do so using a URL. You need to create a URL using the file name.
Because we simply prepended the "/statichtm/" to the file name, and didn't properly extract the name of the file from the Path/FileName your Urls are going to look like:
"/statichtm/D:\PatToVisualStudioProject\1.htm"
Obviously this is not a valid URL....what you really want is just:
"/statichtm/1.htm"
This would have been very obvious if you had used the debugger and stepped through the code.
So what you need to do is fix the ASP code so that the "<td>" is not part of the iframe's src attribute, and modify your loop so that it extracts the file name and then properly create the URLs by prepending "/statichtm/" to the file name extracted.
This is the working VB.NET version of what your code should look like. - Private _repSource As List(Of String)
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
_repSource = New List(Of String)
-
Dim fileNames() As String = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm")
-
For Each name In fileNames
-
Dim sp() As String = name.Split("\"c)
-
Dim urlToStaticHTML As String = sp(sp.Length - 1)
-
_repSource.Add("/StaticHTM/" + urlToStaticHTML)
-
Next
-
staticWebPagesRepeater.DataSource = _repSource.ToArray
-
staticWebPagesRepeater.DataBind()
-
End Sub
-
C# would look something like (the following is obviously not tested): - private List<string> _repSource;
-
protected void Page_Load(Object sender, System.EventArgs e)
-
{
-
_repSource = new List<string>();
-
string fileNames[] = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm");
-
foreach (string name in fileNames)
-
{
-
string sp[] = name.Split('\');
-
string urlToStaticHTML = sp(sp.Length - 1);
-
_repSource.Add("/StaticHTM/" + urlToStaticHTML );
-
}
-
staticWebPagesRepeater.DataSource = _repSource.ToArray();
-
staticWebPagesRepeater.DataBind();
-
}
In the future, please try to debug the problem before automatically asking for help.
@Frinavale
Thank you very much Sir,
I have gotted what i had to do.
thanks a lot again....
u have given a nice answer and made a nice conversetion to me. i really respect u..
bye.. have a nice day
Respected Sir,
thanx a lot for your help now i am facing some other problem . Now i have to display these selected files into gridview/repeater 5 files per page and want to make a custom next and previous button so that when user click next button it's selected radio button item inserted into database and next remaining files will be displayed on the gridview/ repeater template.
Looking for ur reply..
Hi Shashi,
Please take the time to research the problem before you post your question. The experts here are more than willing to help you with a specific problem but you have to do your part to learn the basics.
Once you've tried to solve the problem and you need some help, ask for help on your specific problem.
@Frinavale
Respected Sir....
i have a gridview inside them a radiobuttonlist taken by me. -
<asp:GridView ID="QuestionView1" runat="server" AutoGenerateColumns="False"
-
Width="262px" PageSize="3" AllowPaging="True">
-
<PagerSettings NextPageText="" PreviousPageText="" Visible="False" />
-
<Columns>
-
<asp:TemplateField HeaderText="Questions">
-
<ItemTemplate>
-
<tr>
-
<td> <iframe src="<%# Container.DataItem %>" height="450" width="800"></iframe></td>
-
</tr>
-
<tr>
-
<td align="center" bgcolor="Yellow">
-
<asp:RadioButtonList ID="Answerlist" runat="server" RepeatDirection="Horizontal" ID="radiolist" Font-Bold="True" ForeColor="#0099FF" TextAlign="Left">
-
<asp:ListItem Value="001" Text="Answer 1" ></asp:ListItem>
-
<asp:ListItem Value="002" Text="Answer 2"></asp:ListItem>
-
<asp:ListItem Value="003" Text="Answer 3"></asp:ListItem>
-
<asp:ListItem Value="004" Text="Answer 4"></asp:ListItem>
-
-
</asp:RadioButtonList>
-
</td>
-
-
</tr>
-
</ItemTemplate>
-
-
-
</asp:TemplateField>
-
</Columns>
-
-
</asp:GridView>
but when itry to findout whic radio button has been clicked it shows error, i am really tired . -
RadioButtonList rdo = (RadioButtonList)QuestionView1.Rows[0].FindControl("Answerlist");
-
Response.Write("value has been selected" + rdo.SelectedValue + "<br/>");
looking for your reply....
From Shashi shekhar singh
Hmmm,
What you've posted looks fine...what is the error?
Are you calling the DataBind method for the GridView somewhere near the beginning of the ASP page life cycle (like in the Page Load event)?
-Frinny
PS. I'm not a Sir ;)
@Frinavale
yes sir..
i bind the gridview on page _load and different button click of page like next ,previous, first and last button...
help me out looking for your reply..
Move the databind to the PreRender event instead.
@Frinavale
thank you very much sir, i have got it..that i needed.
Respected Sir,
thanx a lot for your support with me.
This time I have a gridview with multiple button controls inside gridview item template.now i have to check it, out side of the gridview button click event to know which button has been clicked. i am sending my .aspx page plz check it and help me out..
as shown above i want to check it which button has been clicked on -
Button21_Click(object sender, eventargs e)
-
{
-
-
}
plz help me out..waiting for your reply..
This one's a bit tricky.
The only time I've really done something like this I was using dynamic columns and dynamic TemplateFields. The code I implemented for the TemplateField would handle the onclick event and then raise it again so that the page code could handle it.
My guess would be that you'll have to use the GridView.RowCommand event. Remember that the first parameter is the Object that raised the event (which could be your button, but could be something else too)
-Frinny
@Frinavale
When Button out side of the gridview has been clicked then how to determine which button raises the event to to give the source of iframe. ok if i found them by giving the condition
on submit button click... -
if(gridview1.pageindex==0 && btn.text="1")
-
{
-
btn1.enabled =false;
-
}
then it is true only for one postback when next button inside the gridview clicked then it's enabled property =true.
i want to do when submit button clicked then the buutton inside the gridview who raises the src to iframe should be disabled for application lifetime.
Is it possible plz tel me how..it will be possible.
and also tell me how to raise the row_command event in gridview -
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
-
AllowPaging="True" Height="197px" PageSize="1" Width="406px"
-
onrowcommand="GridView1_RowCommand">
-
<PagerSettings Visible="False" />
-
<Columns>
-
<asp:TemplateField HeaderText="Select Questions">
-
<ItemTemplate>
-
</ItemTemplate>
-
void GridView1_RowCommand(objectsender,GridViewCommandEventArgs e)
-
{
-
foreach (GridViewRow row in GridView1.Rows)
-
{
-
Button one = row.FindControl("Button1") as Button;
-
Button two = row.FindControl("Button2") as Button;
-
Button three = row.FindControl("Button3") as Button;
-
Button four = row.FindControl("Button4") as Button;
-
Button five = row.FindControl("Button5") as Button;
-
Button six = row.FindControl("Button6") as Button;
-
Button seven = row.FindControl("Button7") as Button;
-
Button eight = row.FindControl("Button8") as Button;
-
Button nine = row.FindControl("Button9") as Button;
-
Button ten = row.FindControl("Button10") as Button;
-
Button eleven = row.FindControl("Button11") as Button;
-
Button twelve = row.FindControl("Button12") as Button;
-
Button thirteen = row.FindControl("Button13") as Button;
-
Button fourteen = row.FindControl("Button14") as Button;
-
if (GridView1.PageIndex == 0 && one.Text == "1")
-
{
-
one.Enabled = false;
-
-
}
-
if (GridView1.PageIndex == 1 && two.Text == "2")
-
{
-
two.Enabled = false;
-
-
}
-
if (GridView1.PageIndex == 2 && three.Text == "3")
-
-
{
-
three.Enabled = false;
-
-
}
-
string name = e.CommandName;
-
switch (e.CommandName)
-
{
-
case "1":
-
one.Enabled = false;
-
break;
-
case "2":
-
two.Enabled = false;
-
break;
-
-
}
-
}
I should have looked at your code more closely.
I though you were using CommandField buttons not actual Buttons.
Please look into seeing if CommandField controls could be any help to you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dale zhang |
last post by:
Hi,
I build a web form with a 4-cell table on the top (flawlayout), followed by
some labels and textboxes (gridlayout). The web form is displayed well in
dell m60 laptop with all resolution...
|
by: Tina |
last post by:
I'm in a button clicked event on mainpage.aspx. I want to display a new
webpage that has just my image, which is a jpg. I want the page to be a
..jpg not an aspx so that it will be easy for the...
|
by: Rob Meade |
last post by:
Hi all,
I have just put together our organisations 'template' for our web
applications and have created 7 .ascx files which when dropped into my
template file work perfectly...however, I have a...
|
by: David Elliott |
last post by:
I need a control on a Web Page that can accept an HTML Document and will display it.
Any help would be appreciated.
Thanks,
Dave
Here is what I was trying...
|
by: Oleg |
last post by:
I have a web form let's say 'YYZ.aspx'.
It has an iframe in it.
When it loads it shows progress bar in IE this way: loading for page then
again loading for page in iframe.
This part is fine....
|
by: Alan Silver |
last post by:
Hello,
In classic ASP, I used to use two include files on each page, one before
and one after the main content, to provide a consistent layout across a
web site. That way I could just change the...
|
by: Peter Lapic |
last post by:
I have to create a image web service that when it receives an imageid
parameter it will return a gif image from a file that has been stored on the
server.
The client will be an asp.net web page...
|
by: c676228 |
last post by:
Hi everyone,
I have a piece of code in sales.aspx.vb like this:
Protected WithEvents Message As System.Web.UI.WebControls.Label
Try
...
ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr +...
|
by: tomhawkins1 |
last post by:
Hi
I currently have a site where users can upload files. These files can
be doc, wmv, jpeg, xls, dwf, dwf and dwg.
These files are uploaded to /home/**user**/uploads and not /home/...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |