By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Uploading File w/o HtmlInputFile control

P: n/a
I have an application that uses FreeTextBox 2.0
(http://www.freetextbox.com). FreeTextBox is a rich text editor that behaves
similarly to MS Word. The FreeTextBox control has a button to insert images
(just as you would with MS Word) and it works beautifully. The problem is
that when you include an image with the rich text editor, the image path is
the local path on the client. I have written a method that examines the text
for <img> tags, extracts the local path, and then replaces it with what the
virtual path will be after the file has been saved to the server.

I would like post the file to the server as I would with an HtmlInputFile
(PostedFile) control using the HttpPostedFile object, but it would appear
that this is not allowed. After doing some digging, it looks like my best
option would be to write a Web Service that accepts the image as a byte
array and use the WebClient object to upload the file to the service.

It sounds like this would work but I don't really know how to approach this.
I would rather just straight post the file to the HttpPostedFileCollection
just like an HtmlInputFile control does, but that doesn't look like a
possible option. If anyone knows a good means to upload a file without the
HtmlInputFile control, please let me know.

TIA,

Grant Harmeyer
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
what do you mean the htmlinput file is not allowed ?
i have used that object with freetextbox. have a look at this

<form id="Form1" method="post" runat="server">
<table cellSpacing="0" cellPadding="3" width="700" border="0">
<tr>
<td><uc1:moduletitle id="ModuleTitle1" runat="server"
DisplayText="Email Users"></uc1:moduletitle></td>
</tr>
<tr>
<td vAlign="top" align="left"><b>Mailer&nbsp;Subject</b></td>
<td><asp:requiredfieldvalidator id="RFVSubject" runat="server"
Display="Dynamic" ControlToValidate="txtSubject"
ErrorMessage="Subject Required">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<td colSpan="2"><asp:textbox id="txtSubject" runat="server"
MaxLength="100" Columns="50" Width="600px"></asp:textbox></td>
</tr>
<tr>
<td vAlign="top" align="left"><b>Mailer Body</b></td>
<td><asp:requiredfieldvalidator id="RFVBody" runat="server"
Display="Dynamic" ControlToValidate="txtBody" ErrorMessage="Item Text
Required">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<td colSpan="2"><FTB:FREETEXTBOX id="txtBody" runat="server"
Width="600px" BreakMode="LineBreak" DownLevelCols="50"

ToolbarLayout="paragraphmenu,fontsizesmenu,FontFor eColorsMenu,FontBackColors
Menu|bold,italic,underline,Strikethrough, Superscript,
Subscript;JustifyLeft, JustifyRight, JustifyCenter,
JustifyFull;bulletedlist,numberedlist;CreateLink, Unlink; Cut, Copy, Paste,
Undo, Redo"></FTB:FREETEXTBOX></td>
</tr>
<tr>
<td colSpan="2"><b>Mailer&nbsp;Image Navigation URL</b></td>
</tr>
<tr>
<td>
<asp:TextBox id="txtNavigateURL" runat="server" Width="600px"
Columns="50" MaxLength="200"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator id="REVNavigateURL" runat="server"
ErrorMessage="Invalid URL for Image Navigation"
ControlToValidate="txtNavigateURL" Display="Dynamic"
ValidationExpression="http://([\w-]+\.)+[\w-]+(/[\w-
../?%&amp;=]*)?">*</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td colSpan="2"><b>Mailer&nbsp;Image</b></td>
</tr>
<tr>
<td colSpan="2">
<asp:Image id="imgMainImage" runat="server"></asp:Image></td>
</tr>
<tr>
<td colSpan="2"><INPUT id="uploadMainImage" style="WIDTH: 600px"
type="file" size="80" runat="server">
</td>
</tr>
<tr>
<td colSpan="2">&nbsp;</td>
</tr>
<tr>
<td colSpan="2"><aspzone:oneclickbutton id="btnSubmit" runat="server"
Text="Submit"></aspzone:oneclickbutton>&nbsp;&nbsp;&nbsp;&nbsp;
<asp:button id="btnCancel" runat="server" Text="Cancel"
CausesValidation="False"></asp:button><asp:validationsummary
id="ValidationSummary1" runat="server" HeaderText="Errors!! Please correct
the following:"
ShowSummary="False" ShowMessageBox="True"></asp:validationsummary>
</td>
</tr>
</table>
</form>

from code behind

if(Page.IsValid)
{
HttpFileCollection myFiles = Request.Files;
HttpPostedFile myFile = myFiles[0];

MailingListDB mlDB = new MailingListDB();
if((bool)ViewState["isAdd"] == true)
{
mlDB.AddNewMailer(txtSubject.Text.Trim(), txtBody.Text,
txtNavigateURL.Text.Trim(), ref myFile);
}
else
{
mlDB.UpdateExistingMailer((int)ViewState["MailerID"],
txtSubject.Text.Trim(), txtBody.Text, txtNavigateURL.Text.Trim(), ref
myFile);
}

if(ViewState["URLReferrer"] != null)
{
Response.Redirect(Convert.ToString(ViewState["URLReferrer"]));
}
else
{
Response.Redirect("~");
}
}

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Grant Harmeyer" <ne*@internetapollo.com> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl...
I have an application that uses FreeTextBox 2.0
(http://www.freetextbox.com). FreeTextBox is a rich text editor that behaves similarly to MS Word. The FreeTextBox control has a button to insert images (just as you would with MS Word) and it works beautifully. The problem is
that when you include an image with the rich text editor, the image path is the local path on the client. I have written a method that examines the text for <img> tags, extracts the local path, and then replaces it with what the virtual path will be after the file has been saved to the server.

I would like post the file to the server as I would with an HtmlInputFile
(PostedFile) control using the HttpPostedFile object, but it would appear
that this is not allowed. After doing some digging, it looks like my best
option would be to write a Web Service that accepts the image as a byte
array and use the WebClient object to upload the file to the service.

It sounds like this would work but I don't really know how to approach this. I would rather just straight post the file to the HttpPostedFileCollection
just like an HtmlInputFile control does, but that doesn't look like a
possible option. If anyone knows a good means to upload a file without the
HtmlInputFile control, please let me know.

TIA,

Grant Harmeyer

Nov 18 '05 #2

P: n/a
Bad choice of wording on my part, I apologize. Yes the HtmlInputFile control
is allowed, but it doesn't make much sense to have an HtmlFileInput control
on the WebForm for the images that the FreeTextBox control inserts into the
"Text" property. The "Text" property of the FreeTextBox object may contain
several <img> tags, so a single HtmlInputFile control doesn't make much
sense, unless I want to limit users on the placement and number of images
that are allowed.

Again, I apologize if my wording from this post or the previous post seemed
confusing. Thanks for the help.

Grant

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
what do you mean the htmlinput file is not allowed ?
i have used that object with freetextbox. have a look at this

<form id="Form1" method="post" runat="server">
<table cellSpacing="0" cellPadding="3" width="700" border="0">
<tr>
<td><uc1:moduletitle id="ModuleTitle1" runat="server"
DisplayText="Email Users"></uc1:moduletitle></td>
</tr>
<tr>
<td vAlign="top" align="left"><b>Mailer&nbsp;Subject</b></td>
<td><asp:requiredfieldvalidator id="RFVSubject" runat="server"
Display="Dynamic" ControlToValidate="txtSubject"
ErrorMessage="Subject Required">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<td colSpan="2"><asp:textbox id="txtSubject" runat="server"
MaxLength="100" Columns="50" Width="600px"></asp:textbox></td>
</tr>
<tr>
<td vAlign="top" align="left"><b>Mailer Body</b></td>
<td><asp:requiredfieldvalidator id="RFVBody" runat="server"
Display="Dynamic" ControlToValidate="txtBody" ErrorMessage="Item Text
Required">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<td colSpan="2"><FTB:FREETEXTBOX id="txtBody" runat="server"
Width="600px" BreakMode="LineBreak" DownLevelCols="50"

ToolbarLayout="paragraphmenu,fontsizesmenu,FontFor eColorsMenu,FontBackColors
Menu|bold,italic,underline,Strikethrough, Superscript,
Subscript;JustifyLeft, JustifyRight, JustifyCenter,
JustifyFull;bulletedlist,numberedlist;CreateLink, Unlink; Cut, Copy,
Paste,
Undo, Redo"></FTB:FREETEXTBOX></td>
</tr>
<tr>
<td colSpan="2"><b>Mailer&nbsp;Image Navigation URL</b></td>
</tr>
<tr>
<td>
<asp:TextBox id="txtNavigateURL" runat="server" Width="600px"
Columns="50" MaxLength="200"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator id="REVNavigateURL" runat="server"
ErrorMessage="Invalid URL for Image Navigation"
ControlToValidate="txtNavigateURL" Display="Dynamic"
ValidationExpression="http://([\w-]+\.)+[\w-]+(/[\w-
./?%&amp;=]*)?">*</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td colSpan="2"><b>Mailer&nbsp;Image</b></td>
</tr>
<tr>
<td colSpan="2">
<asp:Image id="imgMainImage" runat="server"></asp:Image></td>
</tr>
<tr>
<td colSpan="2"><INPUT id="uploadMainImage" style="WIDTH: 600px"
type="file" size="80" runat="server">
</td>
</tr>
<tr>
<td colSpan="2">&nbsp;</td>
</tr>
<tr>
<td colSpan="2"><aspzone:oneclickbutton id="btnSubmit" runat="server"
Text="Submit"></aspzone:oneclickbutton>&nbsp;&nbsp;&nbsp;&nbsp;
<asp:button id="btnCancel" runat="server" Text="Cancel"
CausesValidation="False"></asp:button><asp:validationsummary
id="ValidationSummary1" runat="server" HeaderText="Errors!! Please correct
the following:"
ShowSummary="False" ShowMessageBox="True"></asp:validationsummary>
</td>
</tr>
</table>
</form>

from code behind

if(Page.IsValid)
{
HttpFileCollection myFiles = Request.Files;
HttpPostedFile myFile = myFiles[0];

MailingListDB mlDB = new MailingListDB();
if((bool)ViewState["isAdd"] == true)
{
mlDB.AddNewMailer(txtSubject.Text.Trim(), txtBody.Text,
txtNavigateURL.Text.Trim(), ref myFile);
}
else
{
mlDB.UpdateExistingMailer((int)ViewState["MailerID"],
txtSubject.Text.Trim(), txtBody.Text, txtNavigateURL.Text.Trim(), ref
myFile);
}

if(ViewState["URLReferrer"] != null)
{
Response.Redirect(Convert.ToString(ViewState["URLReferrer"]));
}
else
{
Response.Redirect("~");
}
}

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Grant Harmeyer" <ne*@internetapollo.com> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl...
I have an application that uses FreeTextBox 2.0
(http://www.freetextbox.com). FreeTextBox is a rich text editor that

behaves
similarly to MS Word. The FreeTextBox control has a button to insert

images
(just as you would with MS Word) and it works beautifully. The problem is
that when you include an image with the rich text editor, the image path

is
the local path on the client. I have written a method that examines the

text
for <img> tags, extracts the local path, and then replaces it with what

the
virtual path will be after the file has been saved to the server.

I would like post the file to the server as I would with an HtmlInputFile
(PostedFile) control using the HttpPostedFile object, but it would appear
that this is not allowed. After doing some digging, it looks like my best
option would be to write a Web Service that accepts the image as a byte
array and use the WebClient object to upload the file to the service.

It sounds like this would work but I don't really know how to approach

this.
I would rather just straight post the file to the
HttpPostedFileCollection
just like an HtmlInputFile control does, but that doesn't look like a
possible option. If anyone knows a good means to upload a file without
the
HtmlInputFile control, please let me know.

TIA,

Grant Harmeyer


Nov 18 '05 #3

P: n/a
well i had a similar problem, the problem is that once on clients page.. the
code is static unless the user posts it.. and there's no way to determine
how many images the user's trying to upload

i would suggest is either limit the number of images or provide a seperate
page for images to uploaded.. ie the user adds the text with placeholders
and then uploads corresponding images seperately.. then you could replace
the placeholders with images at appropriate places.

hth

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Grant Harmeyer" <ne*@internetapollo.com> wrote in message
news:uk**************@TK2MSFTNGP11.phx.gbl...
Bad choice of wording on my part, I apologize. Yes the HtmlInputFile control is allowed, but it doesn't make much sense to have an HtmlFileInput control on the WebForm for the images that the FreeTextBox control inserts into the "Text" property. The "Text" property of the FreeTextBox object may contain
several <img> tags, so a single HtmlInputFile control doesn't make much
sense, unless I want to limit users on the placement and number of images
that are allowed.

Again, I apologize if my wording from this post or the previous post seemed confusing. Thanks for the help.

Grant

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
what do you mean the htmlinput file is not allowed ?
i have used that object with freetextbox. have a look at this

<form id="Form1" method="post" runat="server">
<table cellSpacing="0" cellPadding="3" width="700" border="0">
<tr>
<td><uc1:moduletitle id="ModuleTitle1" runat="server"
DisplayText="Email Users"></uc1:moduletitle></td>
</tr>
<tr>
<td vAlign="top" align="left"><b>Mailer&nbsp;Subject</b></td>
<td><asp:requiredfieldvalidator id="RFVSubject" runat="server"
Display="Dynamic" ControlToValidate="txtSubject"
ErrorMessage="Subject Required">*</asp:requiredfieldvalidator></td> </tr>
<tr>
<td colSpan="2"><asp:textbox id="txtSubject" runat="server"
MaxLength="100" Columns="50" Width="600px"></asp:textbox></td>
</tr>
<tr>
<td vAlign="top" align="left"><b>Mailer Body</b></td>
<td><asp:requiredfieldvalidator id="RFVBody" runat="server"
Display="Dynamic" ControlToValidate="txtBody" ErrorMessage="Item Text
Required">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<td colSpan="2"><FTB:FREETEXTBOX id="txtBody" runat="server"
Width="600px" BreakMode="LineBreak" DownLevelCols="50"

ToolbarLayout="paragraphmenu,fontsizesmenu,FontFor eColorsMenu,FontBackColors Menu|bold,italic,underline,Strikethrough, Superscript,
Subscript;JustifyLeft, JustifyRight, JustifyCenter,
JustifyFull;bulletedlist,numberedlist;CreateLink, Unlink; Cut, Copy,
Paste,
Undo, Redo"></FTB:FREETEXTBOX></td>
</tr>
<tr>
<td colSpan="2"><b>Mailer&nbsp;Image Navigation URL</b></td>
</tr>
<tr>
<td>
<asp:TextBox id="txtNavigateURL" runat="server" Width="600px"
Columns="50" MaxLength="200"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator id="REVNavigateURL" runat="server"
ErrorMessage="Invalid URL for Image Navigation"
ControlToValidate="txtNavigateURL" Display="Dynamic"
ValidationExpression="http://([\w-]+\.)+[\w-]+(/[\w-
./?%&amp;=]*)?">*</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td colSpan="2"><b>Mailer&nbsp;Image</b></td>
</tr>
<tr>
<td colSpan="2">
<asp:Image id="imgMainImage" runat="server"></asp:Image></td>
</tr>
<tr>
<td colSpan="2"><INPUT id="uploadMainImage" style="WIDTH: 600px"
type="file" size="80" runat="server">
</td>
</tr>
<tr>
<td colSpan="2">&nbsp;</td>
</tr>
<tr>
<td colSpan="2"><aspzone:oneclickbutton id="btnSubmit" runat="server" Text="Submit"></aspzone:oneclickbutton>&nbsp;&nbsp;&nbsp;&nbsp;
<asp:button id="btnCancel" runat="server" Text="Cancel"
CausesValidation="False"></asp:button><asp:validationsummary
id="ValidationSummary1" runat="server" HeaderText="Errors!! Please correct the following:"
ShowSummary="False" ShowMessageBox="True"></asp:validationsummary>
</td>
</tr>
</table>
</form>

from code behind

if(Page.IsValid)
{
HttpFileCollection myFiles = Request.Files;
HttpPostedFile myFile = myFiles[0];

MailingListDB mlDB = new MailingListDB();
if((bool)ViewState["isAdd"] == true)
{
mlDB.AddNewMailer(txtSubject.Text.Trim(), txtBody.Text,
txtNavigateURL.Text.Trim(), ref myFile);
}
else
{
mlDB.UpdateExistingMailer((int)ViewState["MailerID"],
txtSubject.Text.Trim(), txtBody.Text, txtNavigateURL.Text.Trim(), ref
myFile);
}

if(ViewState["URLReferrer"] != null)
{
Response.Redirect(Convert.ToString(ViewState["URLReferrer"]));
}
else
{
Response.Redirect("~");
}
}

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Grant Harmeyer" <ne*@internetapollo.com> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl...
I have an application that uses FreeTextBox 2.0
(http://www.freetextbox.com). FreeTextBox is a rich text editor that

behaves
similarly to MS Word. The FreeTextBox control has a button to insert

images
(just as you would with MS Word) and it works beautifully. The problem is that when you include an image with the rich text editor, the image path
is
the local path on the client. I have written a method that examines the

text
for <img> tags, extracts the local path, and then replaces it with what

the
virtual path will be after the file has been saved to the server.

I would like post the file to the server as I would with an

HtmlInputFile (PostedFile) control using the HttpPostedFile object, but it would appear that this is not allowed. After doing some digging, it looks like my best option would be to write a Web Service that accepts the image as a byte
array and use the WebClient object to upload the file to the service.

It sounds like this would work but I don't really know how to approach

this.
I would rather just straight post the file to the
HttpPostedFileCollection
just like an HtmlInputFile control does, but that doesn't look like a
possible option. If anyone knows a good means to upload a file without
the
HtmlInputFile control, please let me know.

TIA,

Grant Harmeyer



Nov 18 '05 #4

P: n/a
or once the user posts the data you could do a scan and redirect a form to
the user which auto submits on load. this for you can have all the parsed
images within htmlfileinput control.

give it a try.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:OZ**************@tk2msftngp13.phx.gbl...
well i had a similar problem, the problem is that once on clients page..
the
code is static unless the user posts it.. and there's no way to determine
how many images the user's trying to upload

i would suggest is either limit the number of images or provide a seperate
page for images to uploaded.. ie the user adds the text with placeholders
and then uploads corresponding images seperately.. then you could replace
the placeholders with images at appropriate places.

hth

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Grant Harmeyer" <ne*@internetapollo.com> wrote in message
news:uk**************@TK2MSFTNGP11.phx.gbl...
Bad choice of wording on my part, I apologize. Yes the HtmlInputFile

control
is allowed, but it doesn't make much sense to have an HtmlFileInput

control
on the WebForm for the images that the FreeTextBox control inserts into

the
"Text" property. The "Text" property of the FreeTextBox object may
contain
several <img> tags, so a single HtmlInputFile control doesn't make much
sense, unless I want to limit users on the placement and number of images
that are allowed.

Again, I apologize if my wording from this post or the previous post

seemed
confusing. Thanks for the help.

Grant

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> what do you mean the htmlinput file is not allowed ?
> i have used that object with freetextbox. have a look at this
>
> <form id="Form1" method="post" runat="server">
> <table cellSpacing="0" cellPadding="3" width="700" border="0">
> <tr>
> <td><uc1:moduletitle id="ModuleTitle1" runat="server"
> DisplayText="Email Users"></uc1:moduletitle></td>
> </tr>
> <tr>
> <td vAlign="top" align="left"><b>Mailer&nbsp;Subject</b></td>
> <td><asp:requiredfieldvalidator id="RFVSubject" runat="server"
> Display="Dynamic" ControlToValidate="txtSubject"
> ErrorMessage="Subject Required">*</asp:requiredfieldvalidator></td> > </tr>
> <tr>
> <td colSpan="2"><asp:textbox id="txtSubject" runat="server"
> MaxLength="100" Columns="50" Width="600px"></asp:textbox></td>
> </tr>
> <tr>
> <td vAlign="top" align="left"><b>Mailer Body</b></td>
> <td><asp:requiredfieldvalidator id="RFVBody" runat="server"
> Display="Dynamic" ControlToValidate="txtBody" ErrorMessage="Item Text
> Required">*</asp:requiredfieldvalidator></td>
> </tr>
> <tr>
> <td colSpan="2"><FTB:FREETEXTBOX id="txtBody" runat="server"
> Width="600px" BreakMode="LineBreak" DownLevelCols="50"
>
> ToolbarLayout="paragraphmenu,fontsizesmenu,FontFor eColorsMenu,FontBackColors > Menu|bold,italic,underline,Strikethrough, Superscript,
> Subscript;JustifyLeft, JustifyRight, JustifyCenter,
> JustifyFull;bulletedlist,numberedlist;CreateLink, Unlink; Cut, Copy,
> Paste,
> Undo, Redo"></FTB:FREETEXTBOX></td>
> </tr>
> <tr>
> <td colSpan="2"><b>Mailer&nbsp;Image Navigation URL</b></td>
> </tr>
> <tr>
> <td>
> <asp:TextBox id="txtNavigateURL" runat="server" Width="600px"
> Columns="50" MaxLength="200"></asp:TextBox>
> </td>
> <td>
> <asp:RegularExpressionValidator id="REVNavigateURL" runat="server"
> ErrorMessage="Invalid URL for Image Navigation"
> ControlToValidate="txtNavigateURL" Display="Dynamic"
> ValidationExpression="http://([\w-]+\.)+[\w-]+(/[\w-
> ./?%&amp;=]*)?">*</asp:RegularExpressionValidator></td>
> </tr>
> <tr>
> <td colSpan="2"><b>Mailer&nbsp;Image</b></td>
> </tr>
> <tr>
> <td colSpan="2">
> <asp:Image id="imgMainImage" runat="server"></asp:Image></td>
> </tr>
> <tr>
> <td colSpan="2"><INPUT id="uploadMainImage" style="WIDTH: 600px"
> type="file" size="80" runat="server">
> </td>
> </tr>
> <tr>
> <td colSpan="2">&nbsp;</td>
> </tr>
> <tr>
> <td colSpan="2"><aspzone:oneclickbutton id="btnSubmit" runat="server" > Text="Submit"></aspzone:oneclickbutton>&nbsp;&nbsp;&nbsp;&nbsp;
> <asp:button id="btnCancel" runat="server" Text="Cancel"
> CausesValidation="False"></asp:button><asp:validationsummary
> id="ValidationSummary1" runat="server" HeaderText="Errors!! Please correct > the following:"
> ShowSummary="False"
> ShowMessageBox="True"></asp:validationsummary>
> </td>
> </tr>
> </table>
> </form>
>
> from code behind
>
> if(Page.IsValid)
> {
> HttpFileCollection myFiles = Request.Files;
> HttpPostedFile myFile = myFiles[0];
>
> MailingListDB mlDB = new MailingListDB();
> if((bool)ViewState["isAdd"] == true)
> {
> mlDB.AddNewMailer(txtSubject.Text.Trim(), txtBody.Text,
> txtNavigateURL.Text.Trim(), ref myFile);
> }
> else
> {
> mlDB.UpdateExistingMailer((int)ViewState["MailerID"],
> txtSubject.Text.Trim(), txtBody.Text, txtNavigateURL.Text.Trim(), ref
> myFile);
> }
>
> if(ViewState["URLReferrer"] != null)
> {
> Response.Redirect(Convert.ToString(ViewState["URLReferrer"]));
> }
> else
> {
> Response.Redirect("~");
> }
> }
>
> --
>
> Regards,
>
> Hermit Dave
> (http://hdave.blogspot.com)
> "Grant Harmeyer" <ne*@internetapollo.com> wrote in message
> news:eB**************@TK2MSFTNGP10.phx.gbl...
>> I have an application that uses FreeTextBox 2.0
>> (http://www.freetextbox.com). FreeTextBox is a rich text editor that
> behaves
>> similarly to MS Word. The FreeTextBox control has a button to insert
> images
>> (just as you would with MS Word) and it works beautifully. The problem is >> that when you include an image with the rich text editor, the image path > is
>> the local path on the client. I have written a method that examines
>> the
> text
>> for <img> tags, extracts the local path, and then replaces it with
>> what
> the
>> virtual path will be after the file has been saved to the server.
>>
>> I would like post the file to the server as I would with an HtmlInputFile >> (PostedFile) control using the HttpPostedFile object, but it would appear >> that this is not allowed. After doing some digging, it looks like my best >> option would be to write a Web Service that accepts the image as a
>> byte
>> array and use the WebClient object to upload the file to the service.
>>
>> It sounds like this would work but I don't really know how to approach
> this.
>> I would rather just straight post the file to the
>> HttpPostedFileCollection
>> just like an HtmlInputFile control does, but that doesn't look like a
>> possible option. If anyone knows a good means to upload a file without
>> the
>> HtmlInputFile control, please let me know.
>>
>> TIA,
>>
>> Grant Harmeyer
>>
>>
>
>



Nov 18 '05 #5

P: n/a

I am trying to use the code suggested by dave. I use the
freetextbox control. Not able to get it working when I insert an image
in the freetextbox control.
The "request.files" Collection is empty inspite of an image being
inserted into the freetextbox.
Any ideas?

Thanks,
Sam.

Hermit Dave wrote:
what do you mean the htmlinput file is not allowed ?
i have used that object with freetextbox. have a look at this

<form id="Form1" method="post" runat="server">
<table cellSpacing="0" cellPadding="3" width="700" border="0">
<tr>
<td><uc1:moduletitle id="ModuleTitle1" runat="server"
DisplayText="Email Users"></uc1:moduletitle></td>
</tr>
<tr>
<td vAlign="top" align="left"><b>Mailer&nbsp;Subject</b></td>
<td><asp:requiredfieldvalidator id="RFVSubject" runat="server"
Display="Dynamic" ControlToValidate="txtSubject"
ErrorMessage="Subject Required">*</asp:requiredfieldvalidator></td> </tr>
<tr>
<td colSpan="2"><asp:textbox id="txtSubject" runat="server"
MaxLength="100" Columns="50" Width="600px"></asp:textbox></td>
</tr>
<tr>
<td vAlign="top" align="left"><b>Mailer Body</b></td>
<td><asp:requiredfieldvalidator id="RFVBody" runat="server"
Display="Dynamic" ControlToValidate="txtBody" ErrorMessage="Item Text
Required">*</asp:requiredfieldvalidator></td>
</tr>
<tr>
<td colSpan="2"><FTB:FREETEXTBOX id="txtBody" runat="server"
Width="600px" BreakMode="LineBreak" DownLevelCols="50"

ToolbarLayout="paragraphmenu,fontsizesmenu,FontFor eColorsMenu,FontBackColors Menu|bold,italic,underline,Strikethrough, Superscript,
Subscript;JustifyLeft, JustifyRight, JustifyCenter,
JustifyFull;bulletedlist,numberedlist;CreateLink, Unlink; Cut, Copy, Paste, Undo, Redo"></FTB:FREETEXTBOX></td>
</tr>
<tr>
<td colSpan="2"><b>Mailer&nbsp;Image Navigation URL</b></td>
</tr>
<tr>
<td>
<asp:TextBox id="txtNavigateURL" runat="server" Width="600px"
Columns="50" MaxLength="200"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator id="REVNavigateURL" runat="server" ErrorMessage="Invalid URL for Image Navigation"
ControlToValidate="txtNavigateURL" Display="Dynamic"
ValidationExpression="http://([\w-]+\.)+[\w-]+(/[\w-
./?%&amp;=]*)?">*</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td colSpan="2"><b>Mailer&nbsp;Image</b></td>
</tr>
<tr>
<td colSpan="2">
<asp:Image id="imgMainImage" runat="server"></asp:Image></td>
</tr>
<tr>
<td colSpan="2"><INPUT id="uploadMainImage" style="WIDTH: 600px"
type="file" size="80" runat="server">
</td>
</tr>
<tr>
<td colSpan="2">&nbsp;</td>
</tr>
<tr>
<td colSpan="2"><aspzone:oneclickbutton id="btnSubmit" runat="server" Text="Submit"></aspzone:oneclickbutton>&nbsp;&nbsp;&nbsp;&nbsp;
<asp:button id="btnCancel" runat="server" Text="Cancel"
CausesValidation="False"></asp:button><asp:validationsummary
id="ValidationSummary1" runat="server" HeaderText="Errors!! Please correct the following:"
ShowSummary="False" ShowMessageBox="True"></asp:validationsummary> </td>
</tr>
</table>
</form>

from code behind

if(Page.IsValid)
{
HttpFileCollection myFiles = Request.Files;
HttpPostedFile myFile = myFiles[0];

MailingListDB mlDB = new MailingListDB();
if((bool)ViewState["isAdd"] == true)
{
mlDB.AddNewMailer(txtSubject.Text.Trim(), txtBody.Text,
txtNavigateURL.Text.Trim(), ref myFile);
}
else
{
mlDB.UpdateExistingMailer((int)ViewState["MailerID"],
txtSubject.Text.Trim(), txtBody.Text, txtNavigateURL.Text.Trim(), ref
myFile);
}

if(ViewState["URLReferrer"] != null)
{
Response.Redirect(Convert.ToString(ViewState["URLReferrer"]));
}
else
{
Response.Redirect("~");
}
}

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Grant Harmeyer" <ne*@internetapollo.com> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl...
I have an application that uses FreeTextBox 2.0
(http://www.freetextbox.com). FreeTextBox is a rich text editor that
behaves
similarly to MS Word. The FreeTextBox control has a button to
insert images
(just as you would with MS Word) and it works beautifully. The
problem is that when you include an image with the rich text editor, the image path is
the local path on the client. I have written a method that examines
the text
for <img> tags, extracts the local path, and then replaces it with
what the
virtual path will be after the file has been saved to the server.

I would like post the file to the server as I would with an
HtmlInputFile (PostedFile) control using the HttpPostedFile object, but it would appear that this is not allowed. After doing some digging, it looks like my best option would be to write a Web Service that accepts the image as a byte array and use the WebClient object to upload the file to the service.
It sounds like this would work but I don't really know how to approach this.
I would rather just straight post the file to the

HttpPostedFileCollection just like an HtmlInputFile control does, but that doesn't look like a possible option. If anyone knows a good means to upload a file without the HtmlInputFile control, please let me know.

TIA,

Grant Harmeyer


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.