Showing posts with label uploading. Show all posts
Showing posts with label uploading. Show all posts

Thursday, March 22, 2012

Strange Page Behavior

Hello to you all.
I have an aspx page with an update panel, and outside that update panel i have a htmlinputfile for uploading some files. It is outside because i understand that htmlinput will not work correctly with an update panel. Near the htmlinputfile i have a Add button and a cancel button. After i add a file, and want to sort a gridview in wich the file is after upload, when the page refreshes the lien execution goes threw the Add button's click event, adding the file again.

Thank you for your time, hope someone can help me with this.

Where are you placing or calling your Add method code? Let us see your code please!

Regards


Here is the markup in the aspx:
<asp:UpdatePanel runat="server" ID="updatePanel" EnableViewState="true">
<ContentTemplate>
<asp:Panel ID="pnlFiles" runat="server">
<asp:GridView ID="grdvFiles" runat="server" AutoGenerateColumns="false" DataKeyNames="FileName" OnRowCommand="grdvFileName_RowCommand" OnRowCreated="grdvFileName_RowCreated" CssClass="datatable" Width="100%" CellPadding="0">
<Columns>
<asp:TemplateField HeaderText="File name">
<ItemTemplate>
<asp:HyperLink Target="_blank" ID="hypAttachment" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DateModified" HeaderText="Date" />
<asp:ButtonField ButtonType="Image" CommandName="_delete" ImageUrl="~/images/delete.gif" />
</Columns>
</asp:GridView>
</asp:Panel>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" DropShadow="true" PopupControlID="pnlModalUpload" TargetControlID="btnModalUpload" CancelControlID="btnCancelAttach" BackgroundCssClass="modal_bg">
</cc1:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>

So this i sthe content of the update panel. The modal popup extender is used to bring up the following panel:

<asp:Panel ID="pnlModalUpload" runat="server" BackColor="#E0E0E0">
<table style="width: 168px">
<tr>
<td>
<input id="fileBrowse" type="file" runat="server" enableviewstate="false" />
</td>
</tr>
<tr>
<td align="center">
<asp:ButtonID="btnAddFile" runat="server" CausesValidation="False" Height="20px" OnClick="btnAddFile_Click" Text="Add" />
<asp:Button ID="btnCancelAttach" runat="server" Text="Cancel" Height="20px" /></td>
</tr>
</table>
</asp:Panel>

And the btnAddFile onclick event is the following:

protected void btnAddFile_Click(object sender, EventArgs e)
{
if (fileBrowse.PostedFile != null & fileBrowse.PostedFile.FileName != "")
{
string fileName = fileBrowse.Value;
fileName = System.IO.Path.GetFileName(fileName);

.........

///here is a work arround the problem i've mentioned

bool addFile = true;
DataSet existingFiles = tvWS.GetFiles(Convert.ToInt32(ViewState["taskID"]));
foreach (DataRow dr in existingFiles.Tables[0].Rows)
if (dr["FileName"].ToString() == fileName)
{
addFile = false;
break;
}
else
addFile = true;

if (addFile)
{
fileBrowse.PostedFile.SaveAs(ConfigurationManager.AppSettings["AttachmentsWrite"] + fileName);
.........

Thank you for your time!

Tuesday, March 13, 2012

Strange Problem in dot net framework 2.0

Hi Experts
We are uploading files on the server using HtmlInputfile control with
visual studio 2005, 2.0. In this there is an option for user to keep on
uploading the files finally file actually uploaded on the server after
clicking Upload Button. So when user add the file we store the content of
HTMLInputfile control in session object. This overall functionality is
working in visual studio 2002, 1.0 environment but the problem we are facing
in 2005 is , The Posted file from session object is becoming “Nothing”
Please let us know the solution.
Thanks & Regards
NetajiYou are confusing technologies a bit. Visual Studio doesn't run on the
server so I assume you mean that the session object is null on a server
running ASP.NET 1.0. Where as, on another server running 2.0 (since they
can't possibly be the same server), the session object works correctly. If
this is correct, review your session time-out settings on the 1.0 server. If
it is not, please explain further.
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
"Netaji" <Netaji@.discussions.microsoft.com> wrote in message
news:C6D35A8B-DCCF-4DD2-BA15-6AEEC572DAB5@.microsoft.com...
> Hi Experts
> We are uploading files on the server using HtmlInputfile control with
> visual studio 2005, 2.0. In this there is an option for user to keep on
> uploading the files finally file actually uploaded on the server after
> clicking Upload Button. So when user add the file we store the content of
> HTMLInputfile control in session object. This overall functionality is
> working in visual studio 2002, 1.0 environment but the problem we are
> facing
> in 2005 is , The Posted file from session object is becoming “Nothing”
> Please let us know the solution.
> Thanks & Regards
> Netaji
>
Hi Alvin
Thank you very much for the reply.
I think it is not session time out issue. becuase on both the server session
are a alive but only one property is getting blank if we execute the same
code in 2.0 framework. below is detail explaination.
We are using htmlinput file control to upload files and storing this
uploaded files across multiple post back in session object which is working
very fine in asp.net 1.0 framework
When we are trying to use the same thing in asp.net 2.0 framework the stored
htmlinputfile content is getting nothing from session . session object is
still there but we are not able to acess the
htmlinputfile.postedfile.filename properties it shows nothing which means
that is is not session expiry problem since all the session are working
properly.
Please let me know if you require more clarification..
Really appriciate your input on this issue...
Thanks
Netaji
"Alvin Bruney [ASP.NET MVP]" wrote:
> You are confusing technologies a bit. Visual Studio doesn't run on the
> server so I assume you mean that the session object is null on a server
> running ASP.NET 1.0. Where as, on another server running 2.0 (since they
> can't possibly be the same server), the session object works correctly. If
> this is correct, review your session time-out settings on the 1.0 server.
If
> it is not, please explain further.
> --
> --
> Regards,
> Alvin Bruney [MVP ASP.NET]
> [Shameless Author plug]
> The O.W.C. Black Book, 2nd Edition
> Exclusively on www.lulu.com/owc $19.99
>
> "Netaji" <Netaji@.discussions.microsoft.com> wrote in message
> news:C6D35A8B-DCCF-4DD2-BA15-6AEEC572DAB5@.microsoft.com...