Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Saturday, March 31, 2012

set a file upload control to a data column within a formview edit item template

I have a formview with an edit template which contains a textbox which has "ProductImageUrl" data column bound to it. I want to bind this to a fileupload control instead so that an image can be selected. There is no text field for a fileupload control.

Any ideas?

Thanks

Andrew

Hi, Andrew

Do you want to get the full path of the image? If so, you can use <input id="file1" type="file" ...> then you can get the full path using fil1.value.

Hope this helps.


Is there a way of just getting the file name and not the full path. Can you give me an example of the code behind for using the fil1.value bit.

Thanks

Andrew


Hello

If you want filename, not the full path, you can useFileUpload control and FileUpload1.FileName is that you want.

As to the code, it's very easy.

<%@. Page Language="C#" AutoEventWireup="True" %>

<script runat="server">

void Button1_Click(object Source, EventArgs e)
{

if (Text1.Value == "")
{
Span1.InnerHtml = "Error: You must enter a file name." + File1.Value;
return;
}

if (File1.PostedFile.ContentLength > 0)
{
try
{
File1.PostedFile.SaveAs("c:\\temp\\" + Text1.Value);
Span1.InnerHtml = "File uploaded successfully to <b>c:\\temp\\" +
Text1.Value + "</b> on the Web server.";
}
catch (Exception exc)
{
Span1.InnerHtml = "Error saving file <b>c:\\temp\\" +
Text1.Value + "</b><br>" + exc.ToString() + ".";


}
}

}
void Click(Object src, EventArgs s)
{
Span1.InnerHtml = File1.Value;
}
</script>

<html>
<head>
<title>HtmlInputFile Example</title>
</head>
<body>

<h3>HtmlInputFile Example</h3>

<form id="Form1" enctype="multipart/form-data"
runat="server">

Select File to Upload:
<input id="File1"
type="file" onselect="Click"
runat="server">

<p>
Save as file name (no path):
<input id="Text1"
type="text"
runat="server">

</p>
<p>
<span id=Span1
style="font: 8pt verdana;"
runat="server" />

</p>
<p>
<input type=button
id="Button1"
value="Upload"
onserverclick="Button1_Click"
runat="server">

</p>

</form>

</body>
</html>

Just click "browser" and then click "upload", the "span" will show the File1.Value.


You can get the file name with the following code

<input type="File" runat="server" ID="InputFile" />

To get the file name use the below line

InputFile.PostedFile.FileName


to get only the filename in a fullpath use

System.IO.Path.GetFileName(fullpath)

HC


The difficult part is that the textbox3 and fileupload controls are within a loginview and a detailsview so doing the findcontrol bit is twisting my melon considerably at the moment.

Any help gratefully received.

Thanks

Andrew


Here is my code

<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate></LoggedInTemplate>
<AnonymousTemplate>
You need to be logged in and be an Administrator to see this page.
</AnonymousTemplate>
<RoleGroups>
<asp:RoleGroup roles="Administrator">
<ContentTemplate>
<h3>Click Edit to view and edit product details and description</h3>
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataSourceID="ObjectDataSource1" Height="50px" Width="100%" DataKeyNames="ProductItemID" AutoGenerateEditButton="True" AutoGenerateInsertButton="True" AutoGenerateDeleteButton="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" OnPageIndexChanging="DetailsView1_PageIndexChanging">
<Fields>
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="ProductDescription" HeaderText="ProductDescription" SortExpression="ProductDescription" Visible="False" />
<asp:BoundField DataField="ProductPrice" HeaderText="ProductPrice" SortExpression="ProductPrice" />
<asp:TemplateField HeaderText="ProductImageUrl" SortExpression="ProductImageUrl">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ProductImageUrl") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ProductImageUrl") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ProductImageUrl") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProductCategoryID" SortExpression="ProductCategoryID">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ProductCategoryID") %>'></asp:TextBox>
cat id<br /> </EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ProductCategoryID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ProductCategoryID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate>
<FTB:FreeTextBox id="ProductDescriptionTextBox" runat="server" Text='<%# Bind("ProductDescription") %>'>
</FTB:FreeTextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate>

</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ProductItemID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<img src="http://pics.10026.com/?src=images/<%# Eval("ProductImageUrl") %>" style="width:100px;" />

</ItemTemplate>
</asp:TemplateField>
</Fields>
<EmptyDataTemplate>
<strong>Product successfully deleted</strong>
</EmptyDataTemplate>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:DetailsView>
<br />
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/editproducts.aspx">Go back to edit products</asp:HyperLink><br />
<br />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="{0}"
SelectMethod="GetDataByProductItemID" TypeName="DataSet3TableAdapters.DataTable1TableAdapter" UpdateMethod="UpdateQuery" InsertMethod="InsertQuery" DeleteMethod="DeleteQuery">
<SelectParameters>
<asp:QueryStringParameter Name="ProductItemID" QueryStringField="ProductItemID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="ProductDescription" Type="String" />
<asp:Parameter Name="ProductPrice" Type="Int32" />
<asp:Parameter Name="ProductImageUrl" Type="String" />
<asp:Parameter Name="WebsiteCategoryID" Type="Int32" />
<asp:Parameter Name="ProductCategoryID" Type="Int32" />
<asp:Parameter Name="ProductItemID" Type="Int32" />

</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductCategoryID" Type="Int32" />
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="ProductDescription" Type="String" />
<asp:Parameter Name="ProductImageUrl" Type="String" />
<asp:Parameter Name="WebsiteCategoryID" Type="Int32" />
<asp:Parameter Name="ProductPrice" Type="Int32" />
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="ProductItemID" Type="Int32" />

</DeleteParameters>
</asp:ObjectDataSource>
<br />
<br />
<br />
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>


</asp:LoginView>

Set application variable from a class

Hi
I am trying to set an application variable from a class file in my website.
Currently, the class file inherits from System.Web.UI.Page
I also referenced all the namespaces a normal webform would.
However, when i try save my application variable like such:
Application["test"] = "hello";
I get the following error:
Object reference not set to an instance of an object
How can i set an application variable from a class
It works fine from a webform
TIA
GrantGot It
HttpContext.Current.Application[ ...
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:%23hZBPQ9NGHA.3984@.TK2MSFTNGP14.phx.gbl...
> Hi
> I am trying to set an application variable from a class file in my
> website.
> Currently, the class file inherits from System.Web.UI.Page
> I also referenced all the namespaces a normal webform would.
> However, when i try save my application variable like such:
> Application["test"] = "hello";
> I get the following error:
> Object reference not set to an instance of an object
> How can i set an application variable from a class
> It works fine from a webform
> TIA
> Grant
>

Set application variable from a class

Hi

I am trying to set an application variable from a class file in my website.

Currently, the class file inherits from System.Web.UI.Page
I also referenced all the namespaces a normal webform would.

However, when i try save my application variable like such:
Application["test"] = "hello";
I get the following error:
Object reference not set to an instance of an object

How can i set an application variable from a class
It works fine from a webform

TIA

GrantGot It

HttpContext.Current.Application[ ...

"Grant Merwitz" <grant@.workshare.com> wrote in message
news:%23hZBPQ9NGHA.3984@.TK2MSFTNGP14.phx.gbl...
> Hi
> I am trying to set an application variable from a class file in my
> website.
> Currently, the class file inherits from System.Web.UI.Page
> I also referenced all the namespaces a normal webform would.
> However, when i try save my application variable like such:
> Application["test"] = "hello";
> I get the following error:
> Object reference not set to an instance of an object
> How can i set an application variable from a class
> It works fine from a webform
> TIA
> Grant

Set as Start Page..

Quick question: when you select "set as start page" for an aspx file,what actually happens? In other words, what file does thatinformation get stored in?
Most likely the .csproj or .vbproj file. It has no impact when you deploy your app. Strictly used for debugging inside VS.Net
Strictly used for debugging inside VS.Net
Oh, okay. That's what I needed to know! Thanks!

If you look in your documents and settings folder, there is a VSWebCache Folder. Each web application will have a folder and in there you'll find a file like WebApplication1.vbproj.user that contains all the user settings like start page.

Monday, March 26, 2012

set default schema on connection string

Hi,
We have a aps.net 2.0 web application and sqlserver 2005.
We keep the connection string in the web.config file.
We need to set the for the web application...
so we do not have to hard code the default schema in every call.
Is it possible to set default schema in the connection string?
Thanks
NalakaHi,
can't you set default schema for the SQL Server user which you use for the
ASP.NET application?
Sample from Books Online
USE AdventureWorks;
ALTER USER Abolrous WITH DEFAULT_SCHEMA = Purchasing;
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Nalaka" <nalaka12@.nospam.nospam> wrote in message
news:uGEIEY5IGHA.2708@.tk2msftngp13.phx.gbl...
> Hi,
> We have a aps.net 2.0 web application and sqlserver 2005.
> We keep the connection string in the web.config file.
> We need to set the for the web application...
> so we do not have to hard code the default schema in every call.
> Is it possible to set default schema in the connection string?
>
> Thanks
> Nalaka
>

set default schema on connection string

Hi,
We have a aps.net 2.0 web application and sqlserver 2005.
We keep the connection string in the web.config file.

We need to set the for the web application...
so we do not have to hard code the default schema in every call.

Is it possible to set default schema in the connection string?

Thanks
NalakaHi,

can't you set default schema for the SQL Server user which you use for the
ASP.NET application?

Sample from Books Online

USE AdventureWorks;
ALTER USER Abolrous WITH DEFAULT_SCHEMA = Purchasing;

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Nalaka" <nalaka12@.nospam.nospam> wrote in message
news:uGEIEY5IGHA.2708@.tk2msftngp13.phx.gbl...
> Hi,
> We have a aps.net 2.0 web application and sqlserver 2005.
> We keep the connection string in the web.config file.
> We need to set the for the web application...
> so we do not have to hard code the default schema in every call.
> Is it possible to set default schema in the connection string?
>
> Thanks
> Nalaka

Set filename in IE Save As dialog for download file?

Hi,

I store attachment file in SQL Server database and user can download it
later by using a download page e.g. Download.aspx?FileID=1234, the problem
is Internet Explorer always show default filename is "Download.aspx" in it's
"Save As" dialog box, how can I force it to display original uploaded
filename (which I save in database too)?

thank you,Well, for example:

string disHeader = "Attachment; Filename=\"" + filename + "\"";
Response.AppendHeader("Content-Disposition", disHeader);
/C

Cristoffer Crusell
Use this code:
Response.AddHeader("Content-Disposition", "inline;filename=test.xls")

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Tien" <tiendq@.gmail.com> wrote in message
news:1d72a31c.0501212036.715c9971@.posting.google.c om...
> Hi,
> I store attachment file in SQL Server database and user can download it
> later by using a download page e.g. Download.aspx?FileID=1234, the problem
> is Internet Explorer always show default filename is "Download.aspx" in
> it's
> "Save As" dialog box, how can I force it to display original uploaded
> filename (which I save in database too)?
> thank you,

Set file name returned from ASP.NET page by URL

Hi!
I have an .aspx page which returns an image. This page takes some GET
parameters, so URL looks like this:
http://localhost/page.aspx?id=1234
Now, when the user click this link, I want that his browser would receive
picture with some good looking name, like image1.jpg.
How to do this within ASP.NET code ?..

--
Pawe
www.DATAX.plWrite an HTTPHandler. Using the Handler, you can make a request for an image
file and get back whatever the handler returns. For example,

http://localhost/image1.jpg?id=1234

would return an image named "image1.jpg" - which could be anything you
generate via your Handler.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I have an .aspx page which returns an image. This page takes some GET
> parameters, so URL looks like this:
> http://localhost/page.aspx?id=1234
> Now, when the user click this link, I want that his browser would receive
> picture with some good looking name, like image1.jpg.
> How to do this within ASP.NET code ?..
> --
> Pawe
> www.DATAX.pl
Thanks for the answer.
Can you shortly tell me what exactly is that HTTPHandler ?.. I cant find
such topic in MSDN.
Paul

"Kevin Spencer" <kevin@.takempis.com> wrote in message
news:%23PRm1$B7DHA.2764@.TK2MSFTNGP09.phx.gbl...
> Write an HTTPHandler. Using the Handler, you can make a request for an
image
> file and get back whatever the handler returns. For example,
> http://localhost/image1.jpg?id=1234
> would return an image named "image1.jpg" - which could be anything you
> generate via your Handler.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "pawel" <pawel.zarzycki@.interia.pl> wrote in message
> news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> > Hi!
> > I have an .aspx page which returns an image. This page takes some GET
> > parameters, so URL looks like this:
> > http://localhost/page.aspx?id=1234
> > Now, when the user click this link, I want that his browser would
receive
> > picture with some good looking name, like image1.jpg.
> > How to do this within ASP.NET code ?..
> > --
> > Pawe
> > www.DATAX.pl
You might try something like this:

Response.Clear();
Response.AddHeader("Content-Disposition","inline;filename=image1.jpg");
Response.WriteFile("myfile.jpg");

Here's more info:
http://msdn.microsoft.com/library/d...tefiletopic.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:%231SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I have an .aspx page which returns an image. This page takes some GET
> parameters, so URL looks like this:
> http://localhost/page.aspx?id=1234
> Now, when the user click this link, I want that his browser would receive
> picture with some good looking name, like image1.jpg.
> How to do this within ASP.NET code ?..
> --
> Pawe
> www.DATAX.pl
Sure. An HttpHandler is a class that handles HTTP requests. In ASP.Net a
Page class, for example, is the default HttpHandler for files with a .aspx
extension. You can map different file extensions to different HttpHandlers
in ASP.Net. What happens is, when the web server receives a request for a
file, it looks in its configuration to find out whether a special
HttpHandler has been designated for that file extension. ASP.Net provides
the HttpHandler class to extend the functionality of ASP.net to be able to
handle requests for other file types (extensions). In IIS, you make ASP.Net
the HttpHandler for the type of file that you desire, and use the web.config
file for your web to identify what DLL (Class Library) is used to handle
specific file extensions.

The HttpHandler is a clsss that handles the request. It has access to the
same HttpContext (Request, Response, Cookies, Session, Application, Server,
etc) that the Page class does.

For more detailed information, see:

http://msdn.microsoft.com/library/d...ttphandlers.asp

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:uLuTwUC7DHA.1052@.TK2MSFTNGP12.phx.gbl...
> Thanks for the answer.
> Can you shortly tell me what exactly is that HTTPHandler ?.. I cant find
> such topic in MSDN.
> Paul
> "Kevin Spencer" <kevin@.takempis.com> wrote in message
> news:%23PRm1$B7DHA.2764@.TK2MSFTNGP09.phx.gbl...
> > Write an HTTPHandler. Using the Handler, you can make a request for an
> image
> > file and get back whatever the handler returns. For example,
> > http://localhost/image1.jpg?id=1234
> > would return an image named "image1.jpg" - which could be anything you
> > generate via your Handler.
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Big things are made up
> > of lots of little things.
> > "pawel" <pawel.zarzycki@.interia.pl> wrote in message
> > news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> > > Hi!
> > > I have an .aspx page which returns an image. This page takes some GET
> > > parameters, so URL looks like this:
> > > http://localhost/page.aspx?id=1234
> > > Now, when the user click this link, I want that his browser would
> receive
> > > picture with some good looking name, like image1.jpg.
> > > How to do this within ASP.NET code ?..
> > > > --
> > > Pawe
> > > www.DATAX.pl
> >

Set filename in IE Save As dialog for download file?

Hi,
I store attachment file in SQL Server database and user can download it
later by using a download page e.g. Download.aspx?FileID=1234, the problem
is Internet Explorer always show default filename is "Download.aspx" in it's
"Save As" dialog box, how can I force it to display original uploaded
filename (which I save in database too)?
thank you,Well, for example:
string disHeader = "Attachment; Filename=\"" + filename + "\"";
Response.AppendHeader("Content-Disposition", disHeader);
/C
Cristoffer Crusell
Use this code:
Response.AddHeader("Content-Disposition", "inline;filename=test.xls")
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Tien" <tiendq@.gmail.com> wrote in message
news:1d72a31c.0501212036.715c9971@.posting.google.com...
> Hi,
> I store attachment file in SQL Server database and user can download it
> later by using a download page e.g. Download.aspx?FileID=1234, the problem
> is Internet Explorer always show default filename is "Download.aspx" in
> it's
> "Save As" dialog box, how can I force it to display original uploaded
> filename (which I save in database too)?
> thank you,

Thursday, March 22, 2012

set icon for website_deploy DLL file

Hi;

How can I set the icon for the DLL file a portla deploy project creates?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htmHello Dave,

As for the setting Icon for the project dll file, do you mean you want your
project's assembly dll has a own Icon as an exe application? If so, I'm
afraid this setting can not be configured individually. It is the windows
shell that controls the icon of each file extension(stored in registry).
And the "exe" is a particular case that the Icon of each exe program can be
defined in the exe itself(as an embeded resource). For other extension
such as "dll", you can only specify a fixed icon for all the files (of that
extension) globally. To do this, you use the "tools-->folder
options-->file types" and use the "advance" setting to change the icon for
all files of a given extension.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
oh - ok.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htm
"Steven Cheng[MSFT]" wrote:

Quote:

Originally Posted by

Hello Dave,
>
As for the setting Icon for the project dll file, do you mean you want your
project's assembly dll has a own Icon as an exe application? If so, I'm
afraid this setting can not be configured individually. It is the windows
shell that controls the icon of each file extension(stored in registry).
And the "exe" is a particular case that the Icon of each exe program can be
defined in the exe itself(as an embeded resource). For other extension
such as "dll", you can only specify a fixed icon for all the files (of that
extension) globally. To do this, you use the "tools-->folder
options-->file types" and use the "advance" setting to change the icon for
all files of a given extension.
>
Sincerely,
>
Steven Cheng
>
Microsoft MSDN Online Support Lead
>
>
This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

set icon for website_deploy DLL file

Hi;
How can I set the icon for the DLL file a portla deploy project creates?
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htmHello Dave,
As for the setting Icon for the project dll file, do you mean you want your
project's assembly dll has a own Icon as an exe application? If so, I'm
afraid this setting can not be configured individually. It is the windows
shell that controls the icon of each file extension(stored in registry).
And the "exe" is a particular case that the Icon of each exe program can be
defined in the exe itself(as an embeded resource). For other extension
such as "dll", you can only specify a fixed icon for all the files (of that
extension) globally. To do this, you use the "tools-->folder
options-->file types" and use the "advance" setting to change the icon for
all files of a given extension.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
oh - ok.
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htm
"Steven Cheng[MSFT]" wrote:

> Hello Dave,
> As for the setting Icon for the project dll file, do you mean you want you
r
> project's assembly dll has a own Icon as an exe application? If so, I'm
> afraid this setting can not be configured individually. It is the windows
> shell that controls the icon of each file extension(stored in registry).
> And the "exe" is a particular case that the Icon of each exe program can b
e
> defined in the exe itself(as an embeded resource). For other extension
> such as "dll", you can only specify a fixed icon for all the files (of tha
t
> extension) globally. To do this, you use the "tools-->folder
> options-->file types" and use the "advance" setting to change the icon fo
r
> all files of a given extension.
> Sincerely,
> Steven Cheng
> Microsoft MSDN Online Support Lead
>
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>

Tuesday, March 13, 2012

Set Print Margin of Web Page

A simple question: I'm trying to set the print margin of a web page automatically so that the user doesn't have to click on File -> PrintPreview -> Page Setup. Anybody know how to do this?
Thanks a lot!As far as I know, you can't do thisdirectly.

In the past I worked on a project where we wanted a report to automatically print "landscape". We had to install a DLL on the client to get this to work, since the printing attributes are set in the client-machine's registry.

From then to now, I don'tthink there has been any script or CSS properties exposed to allow this to be done.

HTH...

Chris

P.S. - one to to try would be to render your data in HTML tables, centered with fixed width's (the smaller the width, the larger the "margin"). Not sure how elegant of a solution that is, but it should work.
Does anyone know if some javascript might do the above? Still looking for a solution. Thanks!
Don't let the title fool you, ...here is a small excerpt from the article (below):


Users can easily change page margins, header and footer settings, and the default Internet Explorer printer through the Internet Explorer user interface. However, there are no methods under Internet Explorer or the WebBrowser control to change these settings programmatically.
HOWTO: Change Print Settings for Internet Explorer and WebBrowser Control Programmatically

Basically, changing printing options DOES involve changing registry settings on the client machine.

Here is one possible solution (it requires a third-party component though, like I described in my previous post):

HTML Printing

HTH...

Chris
Chris,
Thank you for the additional info. I will check it out.
I have been searching for something similar and, like you have not had too much luck. I did find a third party product that lets you have limited control of print setting for free, and more control if you pay...

link:
http://www.meadroid.com/scriptx/indexa.htm

What other options does a developer have for internet base printing? Has anyone had experiences with dynamic acrobat compilers? How about creating MS Snapshot reports dynamically from an asp page?

I can't believe there is nothing else out there.
The Mead control is the one I used in the past...like you said, limited control for free, more for the paid version.

Honestly though, I haven't found anything else that does the job any better (for true browser based printing). Seems if you truly want to control the print job, you need to use some custom control to generate the doc (like PDF of Crystal reports or something).

Chris
regarding using acrobat or crystal to generate a doc ...

do you mean generate a doc on the client-side or the server-side?
You would really most likely want to generate your reports server-side, where you have a better idea of system configuration/power (as well as control over more of the process). You can't count on a user having a fast machine ;-)

HTH...

Chris