Usuário com melhor resposta
Problemas com fileupload ao subir arquivo .xls

Pergunta
-
Bom Dia,
Estou com problemas ao subir um arquivo .xls no meu fileupload mais a propriedade PostedFile vem null, porém quando coloco um arquivo do tipo .jpg ele reconhece...
Segue meu codigo fonte:
private void SubirArquivo()
{
try
{
//Verifica se o arquivo foi postado
if (txtLocalArquivo.PostedFile != null)
{
DirectoryInfo d = new DirectoryInfo(@"C:\\");
if (!Directory.Exists(d + "tempHotshop"))
d.CreateSubdirectory("tempHotshop");
string StrLocalArquivo = "C:\\tempHotshop\\";
string StrNomeArquivo = txtLocalArquivo.PostedFile.FileName.Substring(txtLocalArquivo.PostedFile.FileName.LastIndexOf("\\") + 1);
nomeCaminhoArquivo = StrLocalArquivo + StrNomeArquivo;
string StrFileType = txtLocalArquivo.PostedFile.ContentType;
int IntFileSize = txtLocalArquivo.PostedFile.ContentLength;
if (IntFileSize <= 0)
throw new Exception("Este arquivo esta vazio, favor verificar e tentar novamente. ");
else
txtLocalArquivo.PostedFile.SaveAs(nomeCaminhoArquivo);
}
}
catch (Exception err)
{
throw;
}
}
E meu html:
<asp:UpdatePanel ID="upExcel" runat ="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnCarregar" EventName="Click" />
</Triggers>
<ContentTemplate>
<table id="tbCarregarLote" runat="server" class="tableBlack" border="0" style="width: 718px;"
cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" class="sub_titulo" align="left">
Faça um upload do arquivo excel com a relação de DDD e Telefones para envio de SMS:<br />
<br />
<a href="arquivo_download/PlanilhaSMS.xls" target="_blank"><strong style="font-weight: bold;
color: #ff9900; text-decoration: underline">Clique aqui</strong></a><strong> para baixar
o modelo de planilha.</strong><br />
<br />
</td>
</tr>
<tr>
<td align="right" style="width: 100px">
<span style="text-align: right;"><strong>Arquivo:</strong></span>
</td>
<td width="618" align="left">
<%--<label>
<input name="fileField" type="file" class="texto" id="txtLocalArquivo" runat="server"
style="width: 450px" /></label>--%>
<asp:FileUpload ID="txtLocalArquivo" runat="server" CssClass="texto" EnableViewState="true"
ViewStateMode="Enabled" />
<%--<cc1:AsyncFileUpload ID="txtLocalArquivo" runat="server" UploaderStyle="Modern"/>--%>
</td>
</tr>
<%-- <tr>
<td align="right" style="width: 100px">
<span style="text-align: right;"><strong>Defina a finalidade do arquivo:</strong></span>
</td>
<td class="texto" align="left">
<table width="100%">
<tr>
<td style="width: 180px">
<asp:RadioButtonList ID="rdbTipoArquivo" runat="server" Font-Bold="False" Font-Overline="False"
Font-Size="10px">
<asp:ListItem Value="grupoControle">Grupo de Controle</asp:ListItem>
<asp:ListItem Value="baseTotal" Selected="True">Base Total</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:Label ID="lblAviso" runat="server" Font-Bold="True" ForeColor="Red" Text="Não utilizar caracteres especiais, ex: %, &, ', ", \, /, <,>,{,},º,ª, etc."></asp:Label>
</td>
</tr>
</table>
</td>
</tr>--%>
<tr>
<td style="width: 100px">
<asp:Label ID="Label1" runat="server"></asp:Label>
</td>
<td class="texto" align="left">
<asp:Button ID="btnCarregar" runat="server" align="left" border="0" OnClick="btnCarregar_Click"
Text="Carregar" Width="139px" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
Estou com este problema des de sexta feira e não consigo resolver... rsrsrs
Por favor, me ajudem...
Atenciosamente,
Pedro Henrique
Respostas
-
Consegui..... adicionei uma propriedade contentlenght na tag httpruntime do web config.
- Marcado como Resposta PedroHSantos sexta-feira, 7 de dezembro de 2012 16:38
Todas as Respostas
-
Uma dica: Remova o seu controle de dentro do UpdatePanel. Se quiser um controle assincrono, utilize o AssynFileUpload. Ele tambem faz parte do AjaxControlToolKit.
Seguem umas referencias:
- http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AsyncFileUpload/AsyncFileUpload.aspx
- http://www.codeproject.com/Articles/42865/AsyncFileUpload-Control-New-Control-in-Ajax-Contro
Abraços.
Washington Luíz | MCP, MCTS
O Senhor é minha força e somente Nele confio.- Marcado como Resposta PedroHSantos segunda-feira, 3 de dezembro de 2012 15:30
- Não Marcado como Resposta PedroHSantos segunda-feira, 3 de dezembro de 2012 15:30
- http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AsyncFileUpload/AsyncFileUpload.aspx
-
-
-
-
Consegui..... adicionei uma propriedade contentlenght na tag httpruntime do web config.
- Marcado como Resposta PedroHSantos sexta-feira, 7 de dezembro de 2012 16:38