HttpPostedFile.SaveAs(String) Método
Definição
Salva o conteúdo de um arquivo carregado.Saves the contents of an uploaded file.
public:
void SaveAs(System::String ^ filename);
public void SaveAs (string filename);
member this.SaveAs : string -> unit
Public Sub SaveAs (filename As String)
Parâmetros
- filename
- String
O nome do arquivo salvo.The name of the saved file.
Exceções
A propriedade RequireRootedSaveAsPath do objeto HttpRuntimeSection é definida como true, mas filename não é um caminho absoluto.The RequireRootedSaveAsPath property of the HttpRuntimeSection object is set to true, but filename is not an absolute path.
Exemplos
O exemplo de código a seguir demonstra como salvar todos os arquivos que são carregados pelo cliente para a pasta C:\TempFiles no disco local do servidor Web.The following code example demonstrates how to save all the files that are uploaded by the client to the C:\TempFiles folder on the Web server's local disk.
String TempFileName;
HttpFileCollection MyFileCollection = Request.Files;
for (int Loop1 = 0; Loop1 < MyFileCollection.Count; Loop1++)
{
// Create a new file name.
TempFileName = "C:\\TempFiles\\File_" + Loop1.ToString();
// Save the file.
MyFileCollection[Loop1].SaveAs(TempFileName);
}
Dim Loop1 As Integer
Dim TempFileName As String
Dim MyFileCollection As HttpFileCollection = Request.Files
For Loop1 = 0 To MyFileCollection.Count - 1
' Create a new file name.
TempFileName = "C:\TempFiles\File_" & CStr(Loop1)
' Save the file.
MyFileCollection(Loop1).SaveAs(TempFileName)
Next Loop1
Comentários
O tamanho máximo permitido para uma solicitação, que inclui arquivos carregados, é de 4 MB, por padrão.The maximum size allowed for a request, which includes uploaded files, is 4 MB, by default. O tamanho máximo da solicitação pode ser especificado no arquivo de Machine.config ou Web.config no maxRequestLength atributo do elemento httpRuntime elemento (esquema de configurações ASP.net) .Maximum request size can be specified in the Machine.config or Web.config file in the maxRequestLength attribute of the httpRuntime Element (ASP.NET Settings Schema) element. O tamanho máximo de solicitação para uma página específica pode ser especificado usando o elemento local (esquema de configurações ASP.net) em um arquivo de Web.config.The maximum request size for a specific page can be specified using the location Element (ASP.NET Settings Schema) element in a Web.config file.